[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2753?page=c...
]
Julien Kronegg commented on HHH-2753:
-------------------------------------
Workaround for the "not found=ignore" behavior:
-----------------------------------------------
You can have @ManyToOne with LAZY loading AND without throwing EntityNotFoundException
with the following code:
public MyManyToOneEntity getMyManyToOneEntityOrNull() {
try {
// force fetching the entity (will raise an EntityNotFoundException if not found)
getMyManyToOneEntity().toString(); // or whatever method which force a fetch
return getMyManyToOneEntity();
} catch (EntityNotFoundException e) {
return null;
}
}
This way, Hibernate will issue one query for the main object, and one other query for the
MyManyToOneEntity but only when the getMyManyToOneEntityOrNull() method is called.
not-found="ignore" causes many-to-one to be always eager
--------------------------------------------------------
Key: HHH-2753
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2753
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.1.3, 3.2.2, 3.2.4.sp1
Environment: Tested with 3.1.3, 3.2.2ga, 3.2.4sp1 using Oracle 10g DB.
Reporter: Fred Gurkov
If not-found property of many-to-one mapping is set to "ignore", the
association always gets eagerly initialized regardless of the value of the
"lazy" property.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira