I have one-to-one relationship between these two classes : CrmConfig and PtConfig (actually it is one-to-zero/one relationship).
I want to lazy load the PtConfig otherwise hibernate generates lots of queries to pull PtConfig for each TCrmConfig that is being queried
in few of the reports. I tried to apply lazy=no-proxy for one-to-one on TCrmConfig as shown below with byte code instrumention on. I am
able to solve the problem and now I don't see the hundreds of PtConfig queries when the reports are run. But it introduces another problem,
I can't fetch PtConfig instance even when specifically calling the getter while the session is on i.e. tcrmConfig.getPtConfig() returns null
while database has the row in the t_ptconfig table.
I have tried both constrained=true and constrained=false but did not help.
Hibernate version: 3.2.6a
Code:
The com.xyz.CrmConfig hibernate mapping is as below :
<class
name="com.xyz.CrmConfig"
table="crm..t_crm_config"
lazy="false"
>
<id
name="crmId"
type="java.lang.Long"
column="CrmId"
>
<generator class="identity" />
</id>
<one-to-one
name="ptConfig"
class="com.xyz.PtConfig"
cascade="save-update,delete"
property-ref="crmConfig"
constrained="true"
fetch="join"
lazy="no-proxy">
</one-to-one>
The com.xyz.PtConfig hibernate mapping is as below:
<class
name="com.xyz.PtConfig"
table="md_crm..t_ptconfig"
lazy="false"
>
<id
name="ptConfigId"
type="java.lang.Long"
column="PtConfigId"
unsaved-value="null"
>
<generator class="identity" />
</id>
<many-to-one name="crmConfig"
class="com.xyz.CrmConfig"
column="CrmId"
unique="true"
cascade="none"
lazy="no-proxy"
not-null="true"/>
Why hibernate is not returning the PtConfig instance even when calling the getter? I'm wondering if anybody has come across this situation and can share code sample/realizations.
I'm also wondering if there is any alternative to not use byte code instrumentation (avoid lazy=no-proxy). Please note that I have one-to-zero or one relationship.
Thanks for your help in advance!