This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

merge() operation in hibernate  RSS feed

 
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!