• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CascadeType.MERGE - a good explaination?

 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not having a problem with refresh or delete or persist, but where does the MERGE option come in? When is MERGE significant, and what is the scenario where an entity and it's associated objects would be in a merge scenario?


� CascadeType.MERGE: cascades the merge operation to associated entities if merge() is called or if the entity is managed
-Hibernate Annotations Documentation


Can anyone provide some better clarification for me on the Hibernate and JPS CascadeType.MERGE setting?

Thanks,

-Cameron McKenzie
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the key here, I think, and I could be completely wrong, is that the CascadeType.MERGE option can be thought of as a shallow versus a deep copy of the object.

When you call merge passing a detached object, it will return an object that is now managed. If that detached object has a deeper tree, then what happens to those objects that are "children". Do they get merged with those equivalent objects that is currently being managed, or not? That is where CascadeType.MERGE would come in. With this set, then it is saying merge the child objects with any managed objects currently in the "Session"

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic