Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create table in hibernate if table not exist and then do insert operation?

 
Ajharul Abedeen
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want that if table not exist then it will create table and the insert can be done.
I have written the following code.


But is showing error


Here my problem is that these command is not working same time. I am first creating a table and then doing inserting and i have to change the xml file after creating the table. I want that customer will not have to worry that is there table exist or not.

Now my question that is there any way that i could will able to create table if there table not exist and able to do insert operation same time in same xml file.
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all you can only provide one value for the property "hibernate.hbm2ddl.auto". It is after all a property and properties can only have a single value. So probably whatever is processing that XML file of which you posted a fragment uses the last value it finds, namely "insert". As far as I can see this isn't even a valid value for the property, but my Hibernate experience is out of date; can you show us a document which suggests that you should use "insert"?

When I was using Hibernate I just used "create" for that property and Hibernate would create the tables and permit inserts right away. (There's little point in allowing somebody to create a table and then preventing them from inserting records into it, empty tables are pretty useless.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic