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