Attempted to assign id from null one-to-one property

Description

catch very unexpected exception while updgrading hibernate version 5.2.12 -> 5.2.15
in scenario when
there are object whith null OneToOne property in database
and it is updated with object with non null OneToOne property.

i create test project to reproduce this case - https://github.com/evg345/spring-data-hibernate-bug

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [models.Secunda.parent] at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:90) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105) at org.hibernate.jpa.event.internal.core.JpaMergeEventListener.saveWithGeneratedId(JpaMergeEventListener.java:56) at org.hibernate.event.internal.DefaultMergeEventListener.saveTransientEntity(DefaultMergeEventListener.java:255) at org.hibernate.event.internal.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:235) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:173) at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:905) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:875) at org.hibernate.engine.spi.CascadingActions$6.cascade(CascadingActions.java:261) at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:467) at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:392) at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:193) at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:126) at org.hibernate.event.internal.DefaultMergeEventListener.cascadeOnMerge(DefaultMergeEventListener.java:461) at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:327) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:170) at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69) at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:883) at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:869)

it seems that some versions of Hibernate are broken

  • 5.2.12.Final = GOOD

  • 5.2.13.Final = GOOD

  • 5.2.14.Final = Exception

  • 5.2.15.Final = Exception

  • 5.2.16.Final = Exception

i create test to reproduce https://github.com/evg345/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/HHH12436/OneToOnePropertyTestCase.java
and make pulll request also

Environment

Java 1.8, PostgreSQL, H2Database, Spring-Data 2.0.5

Status

Assignee

Gail Badner

Reporter

evg345

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Worked in

5.1.12
5.1.13

Components

Affects versions

5.2.14
5.2.15
5.2.16

Priority

Major
Configure