3 Replies Latest reply on Dec 6, 2006 9:04 PM by Mark van Leeuwen

    Unnecessary read before update with merge()

    Mark van Leeuwen Newbie

      Hope I'm not posting this to the wrong forum. I raised this first on the EJB3 and Hibernate user forums but have come to the conclusion it is a design / implementation issue with EJB3/Hibernate.

      I have a simple case of an entity which is read in one thread, then updated in another thread using merge().

      The Hibernate merge() code always reads the original value of a detached entity. From DefaultMergeEventListener.entityIsDetached():

       //we must clone embedded composite identifiers, or
       //we will get back the same instance that we pass in
       final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
       .deepCopy( id, source.getEntityMode(), source.getFactory() );
       final Object result = source.get(entityName, clonedIdentifier);

      It should be possible to update the entity without the original value of the entity being read from the DB. This is causing an unncecessary call to the DB.