Specifying Bidirectonal @OneToOne Relation with Shared Primary Key by @Id @JoinColumn annotations does not work.

Description

I have two tables with a shared primary key where userId = id

According to JPA 2.0 Spec 2.4.1.3 Example 4, it should be possible to specify this relationship in at least two ways:

By putting @Id @OneToOne @JoinColumn annotations on the userId field, as in Case (a) of the example,

Or by creating a dummy @Id field, and using @OneToOne @JoinColumn @MapsId annotations on the userId field as in case (b) of the example.

If I specify the relationship as in case (a) AND specify the reverse mapping to UserEntity in UserDetail, then the UserDetail entites returned by queries have their user filed set to null.

If I specify the the relationship as in case (b), OR or I specify the relationship accoring to case (a), but do not specify the reverse mapping in UserEntity, then everything works as expected.

This seems somewhat similar to, and may be related to to HHH-11068, but it affects queries instead of persisting, and triggers with either annotation style.

Reproduction:

1. Create the test tables with records from sharedPKTest.sql, and set up the app server to use it.
2. Build a WAR from the three .java files, and a persistence.xml that points to the db that has the test tables.
3. deploy the war, ( the test runs at deployment time.)
4. Experiment with the commented sections to see which combinations trigger the bug

Environment

Wildfly 10.1 on Centos 7.2 x86_64 , Java 8 and Mysql 5.7.15

Activity

Show:
Tóth István
November 28, 2016, 7:42 PM

I created a maven test case per the guidelines at
https://github.com/stoty/HHH-11279-TestCase

Assignee

Unassigned

Reporter

Tóth István

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure