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

MapsId and flushMode commit causes PersistenceException

Description

If a entity uses @MapsId on another entity you can not persist both of these entities in the same transaction.

Exception obtained:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Caused by: org.hibernate.PropertyAccessException: Could not set field value [<delayed:1>] value by reflection : [class org.hibernate.bugs.ChildEntity.id] setter of org.hibernate.bugs.ChildEntity.id at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:61) at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:259) at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:4936) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:190) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:143) at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:192) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:62) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:800) ... 33 more Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field org.hibernate.bugs.ChildEntity.id to org.hibernate.action.internal.DelayedPostInsertIdentifier at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) at java.lang.reflect.Field.set(Field.java:764) at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:41)

Environment

None

Status

Assignee

Chris Cranford

Reporter

Mårten Bohlin

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.1.14

Affects versions

5.3.6

Priority

Major