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

ClassCastException when using enhanced entities

Description

The attached test case produces a ClassCastException when run (mvn test) with enhancement enabled. It runs fine without.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 2016-07-22 23:01:26,237 DEBUG org.hibernate.SQL - insert into Thing (id) values (null) 2016-07-22 23:01:26,261 DEBUG org.hibernate.SQL - insert into SomeEntity (id, lastChangedAt, parent_id, version) values (null, ?, ?, ?) Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4 sec <<< FAILURE! test(eu.pinske.test.ThingTest) Time elapsed: 3.782 sec <<< ERROR! java.lang.ClassCastException: java.util.HashSet cannot be cast to org.hibernate.collection.spi.PersistentCollection at org.hibernate.event.internal.FlushVisitor.processCollection(FlushVisitor.java:39) at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:104) at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:65) at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:59) at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:155) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:216) at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:85) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1397) at eu.pinske.test.ThingTest.test(ThingTest.java:30)

The exception seems to only occur in these particular circumstances:

  • the entity uses a PreUpdate-hook

  • the entity has a Version-column

  • one collection is created before persist, another one after persist

Unfortunately I was not able to narrow it down further.

Environment

None

Status

Assignee

Luis Barreiro

Reporter

Alexander Pinske

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.2.1

Priority

Major