• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Ajharul Abedeen
Greenhorn
Posts: 21
  • 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: 22215
38
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.)
 
nakul charan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all remove the property :


Then if you are having your entity class with annotation @Table("tablename") and as per exception,
there is a possibility that you are using some fieldname which might be reserved keyword. Can you show your Entity?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!