Results 1 to 2 of 2

Thread: Merge vs. Persist?

  1. #1
    Join Date
    Oct 2011
    Posts
    25

    Default 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 at 08:31 PM.

  2. #2

    Default

    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);
    		}
    	}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •