java.lang.NullPointerException

Hibernate JIRA | Clint Popetz | 6 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    For the following mapping: {code} public class AnEntity extends HibernatePersistedObject { @Id @GeneratedValue private Long id; @OneToOne(optional=false,mappedBy="anEntity") private TargetEntity target; } public class TargetEntity { @Id @GeneratedValue private Long id; @ManyToOne private AnEntity anEntity; } {code} and the following query: {code} AuditReaderFactory.get(em).createQuery(). forRevisionsOfEntity(AnEntity.class,false,false). add(AuditEntity.id().eq(id)).addOrder(AuditEntity.revisionNumber().desc()). setMaxResults(1).getSingleResult() {code} I get an NPE because the there is no EntityConfiguration for TargetEntity, as it is not audited: {noformat} java.lang.NullPointerException at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:81) at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108) at org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:82) at org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:118) at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:100) at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:135) at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108) {noformat}

    Hibernate JIRA | 6 years ago | Clint Popetz
    java.lang.NullPointerException
  2. 0

    For the following mapping: {code} public class AnEntity extends HibernatePersistedObject { @Id @GeneratedValue private Long id; @OneToOne(optional=false,mappedBy="anEntity") private TargetEntity target; } public class TargetEntity { @Id @GeneratedValue private Long id; @ManyToOne private AnEntity anEntity; } {code} and the following query: {code} AuditReaderFactory.get(em).createQuery(). forRevisionsOfEntity(AnEntity.class,false,false). add(AuditEntity.id().eq(id)).addOrder(AuditEntity.revisionNumber().desc()). setMaxResults(1).getSingleResult() {code} I get an NPE because the there is no EntityConfiguration for TargetEntity, as it is not audited: {noformat} java.lang.NullPointerException at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:81) at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108) at org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:82) at org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:118) at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:100) at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:135) at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108) {noformat}

    Hibernate JIRA | 6 years ago | Clint Popetz
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list()
    2. A Hibernate O/RM Module
      AbstractAuditQuery.getSingleResult
      1. org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:81)
      2. org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
      3. org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:82)
      4. org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:118)
      5. org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:100)
      6. org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:135)
      7. org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
      7 frames