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

Classcast issue with new property auditing feature of Envers(withModifiedFlag)

Description

I'm using the latest Hibernate version with Envers support. I have two classes containing a One-To-Many and a Many-To-One relationship:

Code:
@Entity
@Audited(withModifiedFlag = true)
class A {
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "a")
private List<B> bees;
}

@Entity
@Audited(withModifiedFlag = true)
class B {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "aId")
private A a;
}

When saving object A with a list of B object a got the following exception: (updating an object is no problem)

java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.hibernate.collection.spi.PersistentCollection
at org.hibernate.envers.entities.mapper.relation.AbstractCollectionMapper.mapModifiedFlagsToMapFromEntity(AbstractCollectionMapper.java:142)
at org.hibernate.envers.entities.mapper.MultiPropertyMapper.map(MultiPropertyMapper.java:89)
at org.hibernate.envers.synchronization.work.AddWorkUnit.<init>(AddWorkUnit.java:49)

I think the problem is that Envers is trying to track the changes on the collection because it wants to save the audit trail record but the collection is not yet persisted to the database.

Environment

Mysql

Status

Assignee

Lukasz Antoniak

Reporter

Jethro Bakker

Components

Fix versions

Affects versions

4.1.4

Priority

Major