[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5143?page=c...
]
j nadler commented on HHH-5143:
-------------------------------
Right on, that does it. I also had to remove the logic in the setter from the HHH-5109
example, because the setter was triggering the Owned class to load.
In googling this I found a significant # of people having similar problems. Tonight
I'll blog a checklist of all the things that have to go right to get a {One|Many}ToOne
lazy. In the meantime it might be worth adding a few trace-level log statements that show
how the determination of lazy-or-not is made; I would have been able to easily figure this
out without hassling you guys.
Thanks!
Lazy Loading Not Working for @OneToOne Associations With
LazyToOneOption.PROXY
------------------------------------------------------------------------------
Key: HHH-5143
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5143
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.1
Environment: Hibernate Core 3.5.1-Final, MySQL 5.1
Reporter: j nadler
Attachments: OneToOneLoadTest.java
I'm using 3.5.1. Two persistent entities, parent and child, are in a one to one
relationship:
In Parent, the reference to Child:
@OneToOne(optional=false, fetch=FetchType.LAZY, cascade={ CascadeType.MERGE,
CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.PERSIST })
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumn(name = "childId")
@ForeignKey(name="FK_Parent_Child")
@IndexedEmbedded()
public Child getChild() {
return child;
}
public void setChild(Child child) {
this.child = child;
}
And in Child, the reference to Parent:
@OneToOne(mappedBy="child", fetch=FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
@ContainedIn
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent = parent;
}
When I load a Parent entity via HQL, I see three SQL queries:
-one that corresponds to my HQL query
-one that loads Child
-one that loads Parent from the Child's perspective
I'm watching it in JProfiler and it's hurting our app performance significantly
because Child contains LOBs that are rarely needed.
I tried making it a unidirectional association (no reference from Child back to Parent)
but the expensive SQL call (loading Child) still happens. That gets it down to two SQL
queries:
-one that corresponds to my HQL query
-one that loads Child (the expensive one)
We are using the stock javassist proxies and no bytecode enhancement.
--
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