Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate and JPA - Creating Table

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using JPA with EJB, I can persist an entity, without explicitly creating a table with that name. JPA creates a table before persisting the entity into it.
But when I used Hibernate, I can't save an entity, without creating the table. It said "Table not found exception". I had to explicitly create a table before persisting entities. Isn't their any way to automatically create a table when it is needed by Hibernate?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Programatically, you can use the SchemaExport class to recreate a database. It drops everything though, and recreates a blank database.



Here's a little tutorial on using a simple SchemaExport. I'm not sure if this is going to give you the 'create a database table on the fly with Hibernate' type of functionality though. To be honest, I was surprised to hear that an EJB actually would create a database on the fly. That's enough to have every database admin shiver in their boots!

Creating Database Tables with Hibernate and the SchemaExport Class.

-Cameron McKenzie
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cameron
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cameron Wallace McKenzie wrote:To be honest, I was surprised to hear that an EJB actually would create a database on the fly. That's enough to have every database admin shiver in their boots!


No I meant that it would create a table on the fly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic