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

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.1.4

Priority

Major