Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate and JPA - Creating Table

 
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?
 
author and cow tipper
Posts: 5000
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.
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic