Legacy Criteria API: could not resolve Property on One-To-One @PrimaryJoinColumn with hibernate

Description

Criteria API code that searches via associated Entity ID does not work in Hibernate 5.4.1. while it still worked in Hibernate 5.2.18,

This happens if the association is an optional OneToOne mapped with PrimaryKeyJoinColumn. If the association is mapped optional=false the query still works.

The cause seem to be the commit https://github.com/hibernate/hibernate-orm/commit/2bfe30009c15ea59c587d11714d4be78b14f9ad9 and the partial revert in https://github.com/hibernate/hibernate-orm/commit/8535adc05736e9ae93d818d9aff25bf9255a1bbd

The attached test case works with 5.2.18, but fails in 5.4.1.

Environment

None

Activity

Show:
Gail Badner
April 3, 2019, 10:11 PM
Edited

AbstractPropertyMapping#hasNonIdentifierPropertyNamedId is incorrectly returning false when the associated entity ID is named id (as in the attached test).

Fixing AbstractPropertyMapping#hasNonIdentifierPropertyNamedId makes the test pass, but, the resulting query does not do a join with the associated entity table, which is incorrect for an optional one-to-one association.

Also, without fixing AbstractPropertyMapping#hasNonIdentifierPropertyNamedId, the generated SQL for the query "from Foo f where f.bar.id = :barId" properly has a join to the associated entity table.

After fixing AbstractPropertyMapping#hasNonIdentifierPropertyNamedId, the query does not have the join.

Interestingly, changing Bar#id to #id1 (or to anything other than id), the join no longer appears in the generated SQL for "from Foo f where f.bar.id = :barId", which is also a bug.

If/when this is fixed, we need to make sure that it does not cause a regression for JPA/HQL queries.

Gail Badner
April 3, 2019, 10:20 PM

, this doesn't appear to be an issue in 5.3.9, so I removed "5.3+" from the title.

Gail Badner
February 24, 2020, 8:18 PM

A workaround is to use an alias, as in:

Gail Badner
February 26, 2020, 1:04 AM

needs to be fixed before this can be fixed.

Assignee

Unassigned

Reporter

Christian Fraenkel

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.2.18
5.3.9

Components

Affects versions

Priority

Major
Configure