Forums Register Login

New record/row is not getting inserted.Existing record/row is getting updated through hibernate

+Pie Number of slices to send: Send
Hi I am practicing struts with hibernate.I am trying to inserting records through a JSP form.When there is no record in DB one new row is getting
inserted but after that when ever i inserted all the previous are getting removed and only the last record what i inserted is available in database.

Please help me out in this.Should I change anything the hibernate config file ?If required I will put the entire code.Thanks in advance.

regards
Ashwin
+Pie Number of slices to send: Send
It's quite likely that you will have to change something in the configuration, yes. One possible reason for the situation you describe is that you always use the same value for the primary key for all objects. Which might be a configuration problem or a coding problem. And I expect there are other possible reasons.

Would it be fair to assume that you have reduced the problem to updating of only one table? If not, then that's the first step you should take. Find the smallest possible example which fails before you start posting the example. (For more information read SSCCE <-- click that link.)
+Pie Number of slices to send: Send
Paul,

I checked it again.Without restarting the tomcat, if i insert the record everything is fine and records are getting inserted.But if i restart the tomcat and insert the records, all the
previous rows in the table are getting deleted.I understand that this is because I did not commit my previous transaction correctly.But I have used the transaction.commit() statement
in my code.Can you please help me in this ?
+Pie Number of slices to send: Send
 

ashwin bala wrote:
Without restarting the tomcat, if i insert the record everything is fine and records are getting inserted.But if i restart the tomcat and insert the records, all the
previous rows in the table are getting deleted.I understand that this is because I did not commit my previous transaction correctly.



I don't think this is related to transactions. What does your persistence.xml or hibernate.conf.xml (or some such configuration file) look like? There's a setting in there which tells the persistence provider whether to recreate the database or just use the existing database. I guess you have set it to recreate from a clean state every time you restart/redeploy the application.
+Pie Number of slices to send: Send
Thank you Mr.Jai kiran .It worked. I changed the property of "hbm2ddl.auto" from create to update in hibernate.cfg.xml. thanks again.
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 912 times.
Similar Threads
Use of Hibernate to insert million records from Flat File
Insert new records in database without deleting existing records
How to get index value of a row in JTable?
record Insertion problem
Data is getting updated instead of getting Inserted
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:30:07.