-->
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.  [ 4 posts ] 
Author Message
 Post subject: Join association not lazy
PostPosted: Tue Mar 28, 2006 12:27 pm 
Newbie

Joined: Tue Dec 27, 2005 10:39 am
Posts: 9
Hi
I am pretty new to hibernate and I have troubles to make an association lazy. I have a class whose one of its attribute is mapped to clob in different table. My problem is that even with the lazy attribute set to true, the attribute is still loaded.
Here 's my class mapping:




Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="integ2.model">


    <typedef name="StateEnum" class="integ2.dao.hibernate.GenericEnumUserType">
         <param name="enumClass">integ2.model.Job$STATE</param>
    </typedef>
   
    <typedef name="StatusEnum" class="integ2.dao.hibernate.GenericEnumUserType">
         <param name="enumClass">integ2.model.Job$STATUS</param>
         <param name="identifierMethod">getStatusCode</param>
         <param name="valueOfMethod">fromInt</param>
    </typedef>

    <class name="Job" table="jobs" >
       <!-- <cache usage="read-write" region="integ2.model" include="non-lazy"/> -->
        <id name="id">
            <generator class="integ2.dao.hibernate.TableSequenceGenerator">
                <param name="table">sequence</param>
                <param name="tablecolumn">name</param>
                <param name="tablevalue">'jobs'</param>
                <param name="nextid">nextid</param>
            </generator>
        </id>
        <property name="description" column="description" type="string"/>
        <property name="owner" column="owner" type="string"/>
          <property name="status" type="StatusEnum"/>
       
        <map name="stateDates" table="jobstates" lazy="false" sort="unsorted">
            <cache usage="read-write" region="integ2.model"/>
         <key column="jobid" />          
         <index type="StateEnum" column="state"/>
         <element column="statedate" type="timestamp"  not-null="true"/>
        </map>

        <property name="state" type="StateEnum" access="field" column="activestate"/>       
       
       
        <join table="joblogs">
          <key column="jobid"/>
          <property name="logData" type="org.springframework.orm.hibernate3.support.ClobStringType" column="logs" lazy="true"/>
       </join>
        
    </class>

   
</hibernate-mapping>


Here's the SQL code that I get with my named HQL (from Job j where j.stateDates[j.state] > :startDate) :
Code:
Hibernate: select job0_.id as id0_, job0_.description as descript2_0_, job0_.owner as owner0_, job0_.status as status0_, job0_.activestate as activest5_0_, job0_1_.logs as logs2_ from jobs job0_ inner join joblogs job0_1_ on job0_.id=job0_1_.jobid, jobstates statedates1_ where job0_.id=statedates1_.jobid and statedates1_.state = job0_.activestate and statedates1_.statedate>?
Hibernate: select statedates0_.jobid as jobid0_, statedates0_.statedate as statedate0_, statedates0_.state as state0_ from jobstates statedates0_ where statedates0_.jobid=?
Hibernate: select statedates0_.jobid as jobid0_, statedates0_.statedate as statedate0_, statedates0_.state as state0_ from jobstates statedates0_ where statedates0_.jobid=?

As you can see in the first query, the property logData mapped to the logs column of table joblogs is retrieved even if the property is set to lazy.
I checked that bytecode instrumentation was on:
2006-03-28 17:52:53,546 INFO [org.hibernate.cfg.Environment] - using CGLIB reflection optimizer

My JobDAO is a Spring hibernate DAO so the session is supposed to be closed at the end of the method (that retrieves jobs by date). Anyway, I don't understand why the attribute logData is loaded.

I need your help because it really kills my application (logData is mapped to a clob...) I am using Hibernate 3.1.3

Thanks in advance,
Luc


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 12:22 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
If you don't have field-level proxying turned on, then specifying lazy="true" on a value/property does nothing. The default level of proxying is property, not field.

The correct way around this is to eliminate the join, and replace it with an one-to-one association or many-to-one unique="true" association, as appropriate. That kind of association can be proxied with property-level proxying.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 3:53 am 
Newbie

Joined: Tue Dec 27, 2005 10:39 am
Posts: 9
Thanks,

but I don't really understand.
My logData property should be accessed by hibernate with its accessors and the access type is not set to field. So if hibernate default level of proxying is property, the property should be lazy initialized. Or maybe I am confused with the term property (sorry English is not my native language). The lifecycle of the logData property is totally tied to its class Job and is of value type (not entity type).

Code:
      <join table="joblogs">
          <key column="jobid"/>
          <property name="logData" type="org.springframework.orm.hibernate3.support.ClobStringType" column="logs" lazy="true"/>
       </join>



thanks,
Luc[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 5:46 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Property-level proxying means that when you access a property, the object that it's in is deproxied. To defer deproxying of a specific field, it has to be in a different object. Hence using an association does what you need. Join isn't an association, at least not in the same way as a many-to-one: it's used to put more columns into the same object. When the object is deproxied, all of the data necessary to fill the object is retrieved from the database, including anything in another table (via the <join> tag).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.