Announcement Announcement Module
Collapse
No announcement yet.
Merge vs. Persist? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merge vs. Persist?

    Entity Manager has a semantic difference between Merge and Persist, however, I notice that the base Data dao just has a "save" method. Does that correspond to the Merge, or is there code that intelligently checks with an exist call and persist if the call returns false?

    edit: The reason I ask is that it looks like I may have run into a hibernate issue with OneToMany and deleteOrphan=true. On a merge(which is mapped to EntityManager.merge) Hibernate seems to issue an update setting the join column to null first, before deleting it. On a saveOrUpdate, (mapped to EntityManager.persist) Hibernate does the right thing and issue the delete straightaway...

    Jeff
    Last edited by swang30; Feb 8th, 2012, 09:31 PM.

  • #2
    swang,

    This usually is an issue with how you have your relationships mapped. But FYI the implementation for save is as follows:
    Code:
    	@Transactional
    	public T save(T entity) {
    
    		if (entityInformation.isNew(entity)) {
    			em.persist(entity);
    			return entity;
    		} else {
    			return em.merge(entity);
    		}
    	}

    Comment

    Working...
    X