• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate and JPA - Creating Table

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cameron
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No more fooling around. Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic