• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

merge() operation in hibernate

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator








Q1)using get() bring detached object back to persistent state and makes some changes these changes are getting added successfully.But
once again i am opening new session using get() second time and search the same entity and further make some modification,but now these changes
are not getting added ? Why?

Q2) What is use merge()?

 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
merge() method copies the content of detached instance to the persistent instance which has the same identifier...

detached objs reference pointing "sathyajeet" object contain email as "testing@yahoo1.com".

Since merge() does copying of content from "objs" object to the existing persistent object containing email "final@yahoo.com", "testing@yahoo1.com" replaces the "final@yahoo.com"... So, not getting updated.

And

since the object with "sathyajeet" identifier retrieved using get() method is mapped to "sathyajeet" primary key, changing the identifier of an existing persistent instance ends up in that identifier change violation exception
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic