1 Reply Latest reply on Jul 5, 2013 11:46 AM by Krutika S

    NPE with forRevisionsOfEntity query on an entity with a @ManyToOne relation

    Krutika S Newbie



      I have 2 entities Limits and UserGroup where Limits is audited and UserGroup is not. They are audited ad follows-

      Entity Limits-


      @Table(name = "LMT")

      public final class LMT {



          @JoinColumn(name = "OWNER_GROUP_ID", referencedColumnName = "ID")

          @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)

          private UserGroup ownerGroup;




      Entity UserGroup-


      @Table(name = "ENT_USER_GROUPS")


      public final class UserGroup


      OneToMany and ManyToMany relations with other entities

      attributes and methods



      The problem i am facing is when querying for revisions of enitity Limits using forRevisionsOfEntity-

      AuditQuery query3 = reader.createQuery().forRevisionsOfEntity(Limits.class, true, false).add(AuditEntity.id().eq(2186));

                            System.out.println("results3 -------- "  + " " +  query3.getResultList());


      This gives a NPE as follows-



                at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:755)

                at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4129)

                at org.hibernate.envers.entities.mapper.relation.ToOneIdMapper.mapToEntityFromMap(ToOneIdMapper.java:101)

                at org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:115)

                at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:99)

                at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:134)

                at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:102)

                at com.LimitChangesTest.test_get_all_limit_changes(LimitChangesTest.java:124)


      However, if comment out the @Audited(..) annotation for ownerGroup or put a @NoTAudited i.e on not auditing it, the query returns the revisions of entity Limits( with ownerGroup=null). I have used RelationTargetAuditMode.NOT_AUDITED for ownerGroup  as the entity is not audited. So i am guessing the annotations are right, but i can't figure out why auditing this property is causing a NPE.