This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate cascade question

 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

I do not quite understand the use of the merge, persist, and refresh.

can anyone explain to me? and give me some examples.

Thank you
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merge when you have a detached object and you want to re-attach it to a Hibernate Session, you need to merge, so that Hibernate can do some work, like checking the managed objects to see if one with that id already exists, and if so check to see if they are the same objects, so that there is only one instance in the Session, because if you try to do persist(), which is like saveOrUpdate, then it will see that there is already an object with that id and throw a NonUniqueObjectException.

With persist() that is like calling saveOrUpdate, in which Hibernate will determine if there needs to be an insert or an update statement created.

refresh, is telling Hibernate to go back to the database and refresh the object that it has in its Session, which could be stale.

The thing is "cascade" isn't in your question, so I am confused at the topic name.

Mark
 
jim li
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
rajkumar nirala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check hibernate tutorial.. good one http://www.techfaq360.com/tutorial/hibernate.jsp
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic