Composite ID containing foreign Composite ID loading incorrectly.

Description

After following an example (http://docs.jboss.org/hibernate/core/4.3/manual/en-US/html_single/#d5e2288) on how to create a composite ID that contained a foreign composite ID, I ran into some issues with the data. Based on that example, the JPA supported method will be referred to as Option 1 (the one I want to use) and the other is Option 2. This issue is with Option 1.

The database and models were made to test various Hibernate scenarios, so I apologize if they are a bit harder to follow.

I have the following data (scripts have been attached to recreate):

PrimaryKey table

CompositeKey table

PrimaryCompositeKey table

We created a custom annotation to handle Hibernate @Entity defaults for our models:

HibernateDefaultEntity.java

and the following models:

PrimaryKeyModel.java

CompositeKeyModel.java

CompositeKeyModelId.java

PrimaryCompositeKeyOption1Model.java

PrimaryCompositeKeyOption1ModelId.java

Now, when I use the following test:

My output looks like:

Option 1 output,

The CompositeKeyModelId referenced by the PrimaryCompositeKeyModelId does not contain the same data as the CompositeKeyModelId referenced by the CompositeKeyModel association. Additionally, the descriptions for both the PrimaryCompositeKeyModel and CompositeKeyModel is the same as the previous model every other model (i.e. no PCK1/CK1, PCK3/CK3, or PCK5/CK5). Bizarre.

I checked the query being generated, and it is selecting compositeId1 twice:

Other than the extra column, the data it returns is correct:

This does not happen with Option 2:

PrimaryCompositeKeyOption2Model.java

PrimaryCompositeKeyOption2ModlId.java

Option 2 output

As you can see, the extra column doesn't exist in this scenario, which leads me to believe it is the culprit.

Attachments

3

Activity

Show:

Christian Beikov April 8, 2022 at 5:08 PM

I'm pretty sure this is fixed in 6.0. If this still is an issue for you, please create a new issue with a test case that reproduces the problem on the latest Hibernate version.

Steve Ebersole October 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 7:14 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Out of Date

Details

Assignee

Reporter

Labels

Components

Affects versions

Priority

Created May 20, 2014 at 10:09 PM
Updated April 8, 2022 at 5:08 PM
Resolved April 8, 2022 at 5:08 PM