This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using MySQL with Hibernate, a small application, inserting record into table Person, which was created as :
To my surprise, every time I run app (so i am inserting a record) - record is getting updated with same id:
mysql> select * from person;
| PERSON_ID | PERSON_NAME |
| 1 | BOMBAYite |
1 row in set (0.00 sec)
NOTE --- I even tried by inserting more records by command line - they are gettign inserted & total records shoes 4.
But the moment I run my Hibernate app - all records are gone - just the latest (being inserted) is shown.
Can you share the peace of code where you are setting Person bean and calling hibernate session to save the object.
Joined: Dec 23, 2008
I thing the problem is with AUTO_INCREMENT=3 defined in your sql create statement.
when you are using hibernate native class, it issues an select statement to retrieve next id from database.
query is of format (select max(PERSON_ID) from person )
the same is also missing in your log file.
I would suggest you to try the above example without using "AUTO_INCREMENT=3 " option.