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

@OneToOne Derived ID is null when returned by query when bidirectional

Description

Given the following entities:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 @Entity public class Bar { @Id @OneToOne private Foo foo; ... } @Entity public class Foo implements Serializable { @Id private Long id; @OneToOne(mappedBy = "foo") private Bar bar; ... }

When the following query is executed:
"SELECT f FROM Foo f"

Bar objects that get returned have a null ID (i.e., bar#foo == null)

This happens because the fix for sets ToOne#referenceToPrimaryKey for Bar#foo to false [1], which ultimately leads to the ID not being resolved. [2]

[1] https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java#L227
[2] https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/type/EntityType.java#L428-L439

Environment

None

Status

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.10
5.0.12
5.1.9
4.2.21

Priority

Major