AuditException / NullPointerException when loading audited entity with embeddable referencing non-audited entity in Hibernate

Solution Verified - Updated -

Issue

  • Defined an audited entity which has an association to an audited embeddable which, in turn, contains a reference to a non-audited entity

    @Audited
    public class Parent {
        ...
        @ElementCollection
        @CollectionTable(name = "items", joinColumns = @JoinColumn(name = "PRODUCT_ID"))
        @OrderColumn(name = "ORDER_COL")
        @Audited
        private List<Item> items = new ArrayList<Item>();
    }
    
    @Embeddable
    @Audited
    public class Item {
        ...
        @ManyToOne
        @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
        private Type type;
    }
    
  • The following exception is raised when loading the "parent" entity

    org.hibernate.envers.exception.AuditException: java.lang.NullPointerException
        at org.hibernate.envers.internal.entities.mapper.relation.component.MiddleEmbeddableComponentMapper.mapToObjectFromFullMap(MiddleEmbeddableComponentMapper.java:55)
        at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:66)
        ...
        at org.hibernate.envers.internal.reader.FirstLevelCache.putOnEntityNameCache(FirstLevelCache.java:87)
        at org.hibernate.envers.internal.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:111)
        at org.hibernate.envers.internal.entities.EntityInstantiator.addInstancesFromVersionsEntities(EntityInstantiator.java:164)
        at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.applyProjections(AbstractAuditQuery.java:336)
        at org.hibernate.envers.query.internal.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:128)
        at org.hibernate.envers.query.internal.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:111)
        at org.hibernate.envers.internal.reader.AuditReaderImpl.find(AuditReaderImpl.java:124)
        at org.hibernate.envers.internal.reader.AuditReaderImpl.find(AuditReaderImpl.java:93)
        at org.hibernate.envers.internal.reader.AuditReaderImpl.find(AuditReaderImpl.java:87)
        ...
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7.0
  • Hibernate 5.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content