5 Replies Latest reply on May 28, 2013 5:57 AM by anthonyb

    [RESOLVED] Hibernate-Envers 3.6.10-Final with ValidityAuditStrategy throws NonUniqueObjectException

    anthonyb Newbie

      Hello,

       

      I'm working on an application based on Hibernate-Envers 3.6.10-Final where we have chosen to use the strategy ValidityAuditStrategy, due to the very critical performance issues of the default strategy we have encountered.

       

      However, during the lazy loading entities process, the "find" method which should returns only the last revision of one entity can bring more than one result.

       

       

      I have managed to identify where the problem occured. This is inside the AuditReaderImpl class, in the find(Class<T>, String, Object, Number) method:

      result = createQuery().forEntitiesAtRevision(cls, entityName, revision).add(AuditEntity.id().eq(primaryKey)).getSingleResult();

      I have changed the "getSingleResult()" by a "getResultList().get(0)" to see if the global process was working and this was fine (except the first value may not be the right one). Otherwise, the NonUniqueObjectException is thrown.

       

      It seems that the query is only based on the primary key "id" and does not take into account other primary keys of the related table. In our audit tables, there is also the "REV" colmun in the primary key, and sometimes other columns. If we take only the "id", there are duplicates but if we considered the REV column, our table contains no duplicates entries.

       

       

      Here is how the related entity is configured:

      @MappedSuperclass
      public abstract class GenericConfiguration extends LockableModel {
      
      
          //Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
          @Required
          //everyone but REMOVE
          @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.DETACH, CascadeType.MERGE})
          @JoinColumn(name = "applicationBranch", nullable = false)
          public ApplicationBranch applicationBranch;
      
      
          @ManyToMany(cascade = CascadeType.ALL)
          @Audited
          public List<PropertyValue> properties; // FIXME ABN: Le fait que ça soit auditer fait perdre du temps

      The lazy entity example here is "properties". With the default strategy, this entity was correctly loaded, but with the critical performance issues I've mentionned.

       

      Then the PropertyValue entity class:

      @Audited
      @Entity
      @Table(name="PVALUE")
      public class PropertyValue extends Model implements Comparable {

       

      Is there anything that I should do or check to make this strategy work fine on my application ? Do you need other information to analyze my problem ?

       

      I think I have correctly populated the REVEND column and I have succeded in seeing a hibernate query containing this REVEND column, whereas with the default strategy this column was never used.

       

      Here is the only configuration regarding this new audit strategy:

      <property name="org.hibernate.envers.audit_strategy" value="org.hibernate.envers.strategy.ValidityAuditStrategy" />

       

       

      Thank you in advance.

      Regards,