I tried all possible combinations to prevent (N+1), nothing works.
Our mapping looks like:
-------------------------------------------
<class “User” lazy=”false”>
<many-to-one name="security" cascade="lock" column="SECURITYID" class="Security" not-null="false" lazy="no-proxy" access="field">
</many-to-one>
<set name="history" lazy="true" cascade="save-update,lock" inverse="true">
<key column="USERID" not-null="true"/>
<one-to-many class="History"/>
</set>
<one-to-one name="profile" class="Profile" cascade="save-update,lock" lazy="no-proxy" access="field"/>
</class>
<class “History” lazy=”false”>
<many-to-one name="user" cascade="lock" column="USERID" class="User" not-null="true" lazy="no-proxy" access="field">
</many-to-one>
</class>
-------------------------------------------------
retrieveUser(userid) -- retrieves everything in one JOIN, which is fine.
retrieveHistory(historyid) – generating 3-SQLs (one JOIN-fine, 2-extra selects one
on User.Profile & one on User.Security.
How to prevent SELECTs on Profile & Security.
This is really affecting performance. I also tried with other LAZY options on User.Security&Profile, varying fetch_depth, but nothing works.
Our client is very upset, don’t want to use Hibernate any more!
I would appreciate your help.
Thanks.
|