Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
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.
 
Sheriff
Posts: 24654
58
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.)
 
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?
 
I will open the floodgates of his own worst nightmare! All in a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!