Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

hibernate SaveUpdate

  Asked By: Bonni    Date: Aug 02    Category: Java    Views: 701
  

I have a Hibernate question.
I am using SaveUpdate() method to upadate/save an object to db.
I assume that it should know when to update and when to save it based on if i have populated pk in my pojo.
but it doesnt update at all and it is always saving it as a new row in db.
even i tried to test it with
MyObj foundObj = getObjFromDbById(long key);-----------------> so it has primary key populated

HibernateTemplate.saveUpdate(foundObj );
and it saved it again... what is wrong???

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Ray Lawrence     Answered On: Aug 02

To use saveOrUpdate() function of hibernate  you have to set attribute of your PK to "increment" in hbm.xml file related to your pojo.
when you try to use this function , note that not to set the primary key  and either in editing mode just fetch it from db once.
the hibernate checks the value of PK and decides to insert or edit a record itself.
the key point is that u use the correct style for PK which is "increment" in this case.

 
Didn't find what you were looking for? Find more on hibernate SaveUpdate Or get search suggestion and latest updates.




Tagged: