-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: one-to-(zero-or-one) lazy load with no-proxy issue
PostPosted: Fri Oct 31, 2008 11:28 am 
Newbie

Joined: Thu Jan 31, 2008 1:48 pm
Posts: 11
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!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2008 2:29 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
I am not familiar with byte-code instrumentation, but can offer a slightly ugly work-around:

As you correctly realized, the setting "proxy" can not work for a nullable ToOne-Association, because no proxy can pretend to be the null pointer.

A ToMany-association can be proxied even if nullable, and convenience accessors can hide the sets involved from application code. Of course, application code and queries would then have to use different property names.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.