java.lang.NullPointerException

Hibernate JIRA | Andrey Yakovlev | 2 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

    A problem occurrs with the following mapping: {code} @Entity public class Person { @Id @GeneratedValue private Integer id; @Audited private String name; @Audited @OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OrderColumn(name = "index") private List<Document> documents; // getters, setters } @Entity public class Document { @Id @GeneratedValue private Integer id; @Audited private String contents; @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @ManyToOne @JoinColumn(name = "person_id") private Person person; // getters, setters } {code} It seems that in this case Envers ignores OrderColumn annotation and creates document_AUD table without index column: {code:sql} create table Document ( id integer generated by default as identity (start with 1), contents varchar(255), person_id integer, index integer, primary key (id) ) create table Document_AUD ( id integer not null, REV integer not null, REVTYPE tinyint, contents varchar(255), person_id integer, primary key (id, REV) ) {code} If we add index column manually it will always stay empty. And then if we try to access documents in Project revision it fails with NPE: {noformat} java.lang.NullPointerException at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:91) at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:40) at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:71) at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50) at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.iterator(CollectionProxy.java:74) {noformat} I think it's defenitely a bug. What are possible work-arounds? I attached a simple project with hsqldb that reproduces this bug.

    Hibernate JIRA | 2 years ago | Andrey Yakovlev
    java.lang.NullPointerException
  2. 0

    A problem occurrs with the following mapping: {code} @Entity public class Person { @Id @GeneratedValue private Integer id; @Audited private String name; @Audited @OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OrderColumn(name = "index") private List<Document> documents; // getters, setters } @Entity public class Document { @Id @GeneratedValue private Integer id; @Audited private String contents; @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @ManyToOne @JoinColumn(name = "person_id") private Person person; // getters, setters } {code} It seems that in this case Envers ignores OrderColumn annotation and creates document_AUD table without index column: {code:sql} create table Document ( id integer generated by default as identity (start with 1), contents varchar(255), person_id integer, index integer, primary key (id) ) create table Document_AUD ( id integer not null, REV integer not null, REVTYPE tinyint, contents varchar(255), person_id integer, primary key (id, REV) ) {code} If we add index column manually it will always stay empty. And then if we try to access documents in Project revision it fails with NPE: {noformat} java.lang.NullPointerException at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:91) at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:40) at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:71) at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50) at org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.iterator(CollectionProxy.java:74) {noformat} I think it's defenitely a bug. What are possible work-arounds? I attached a simple project with hsqldb that reproduces this bug.

    Hibernate JIRA | 2 years ago | Andrey Yakovlev
    java.lang.NullPointerException

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection()
    2. org.hibernate.envers
      CollectionProxy.iterator
      1. org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:91)
      2. org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:40)
      3. org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:71)
      4. org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
      5. org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.CollectionProxy.iterator(CollectionProxy.java:74)
      5 frames