Lazy fetch for OneToOne associations doesn't seem to work for method annotated classes

Description

For OneToOne associations where annoations are on the getter methods rather than on the properties, lazy fetch does not work. The load query triggers a full load (extra queries for the associated entities) even before the associated entities themselves are accessed via the getters.

When the annotations are moved to the properties (entity references) the associated entities are loaded only when accessed.

Environment

Hibernate 3.3.2.GA_CP05/EAP 5.2.0 (also confirmed in latest EAP 6.3.1 integrated Hibernate release)
All databases

Activity

Show:
Gail Badner
October 16, 2014, 6:54 AM

The "failing" lazy @OneToOne associations in Person both have mappedBy="owner"; the "working" lazy @OneToOne associations in Person does not have mappedBy.

Stephen Fikes
October 17, 2014, 1:20 AM
Edited

The mappedBy was missing from the "working" test ... but that is required to ensure that an extra foreign key is not generated in the Person table. After adding the mappedBy to the "working" test ... it also fails to work correctly - which is to say, fetching the pet4 and pet5 entities is not done lazily. The fetch is performed aggressively (two extra queries) when executing the Person query. From the table mappings, I'm not understanding why the extra query would be required.

The model can be simplified as below and the underlying table for Person will have nothing more than its key, and the table for Pet4 will have its key and owner_id as a foreign key to person. Using the same basic test code, it can be seen that the query for person also results in a second query for Pet4.

Brett Meyer
April 22, 2015, 9:14 PM

Closing rejected issues.

Assignee

Gail Badner

Reporter

Stephen Fikes

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure