We're updating the issue view to help you get more done. 

NullPointerException with indexed Collections

Description

The Hibernate Developers Guide in version 4.1 writes in chapter "15.11.1 What isn't and will not be supported" "

Bags (the corresponding Java type is List), as they can contain non-unique elements. The reason is that persisting, for example a bag of String-s, violates a principle of relational databases: that each table is a set of tuples. In case of bags, however (which require a join table), if there is a duplicate element, the two tuples corresponding to the elements will be the same. Hibernate allows this, however Envers (or more precisely: the database connector) will throw an exception when trying to persist two identical elements, because of a unique constraint violation.

There are at least two ways out if you need bag semantics:

use an indexed collection, with the @IndexColumn annotation, or

provide a unique id for your elements with the @CollectionId annotation." However Envers throws a NullPointerException in OneToMany relations with indexed collections.

Stacktrace:

java.lang.NullPointerException
at org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:75)
at org.hibernate.envers.entities.mapper.relation.lazy.initializor.ListCollectionInitializor.addToCollection(ListCollectionInitializor.java:39)
at org.hibernate.envers.entities.mapper.relation.lazy.initializor.AbstractCollectionInitializor.initialize(AbstractCollectionInitializor.java:67)
at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.checkInit(CollectionProxy.java:50)
at org.hibernate.envers.entities.mapper.relation.lazy.proxy.CollectionProxy.size(CollectionProxy.java:55)
at org.hibernate.envers.test.tools.TestTools.checkList(TestTools.java:63)
at org.hibernate.envers.test.integration.onetomany.IndexedBasicList.testHistoryOfEdId2(IndexedBasicList.java:109)

Environment

None

Status

Assignee

Chris Cranford

Reporter

Christian Drees

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.2
4.1.12
4.3.11
5.2.1
5.0.10
3.6.10
4.2.21

Priority

Critical