Issue Type: Bug Bug
Affects Versions: 4.1.7
Assignee: Unassigned
Components: envers
Created: 24/Jan/13 7:04 AM
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)

Project: Hibernate ORM
Priority: Critical Critical
Reporter: Christian Drees
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira