-->
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.  [ 6 posts ] 
Author Message
 Post subject: lazy=true and left join fetch
PostPosted: Mon Oct 06, 2003 4:17 pm 
Newbie

Joined: Mon Oct 06, 2003 2:20 pm
Posts: 10
Hi ,

I have a mapping like this, i give it one-to-many the lazy=true and i want to use left join fetch to get my two children list, here is my query

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

<hibernate-mapping>
<class name="com.sp.fbb.businessobject.investpolicy.InvestPolicy" table="FBB_INVESTMENT_POLICY">

<id column="INVPOL_ID" name="investPolicyID" type="long" >
<generator class="assigned"/>
</id>

<property column="INVPOL_DESCRIPTION" length="1024" name="comments" type="string"/>
<property column="INVPOL_INVESTMENT_AMOUNT" name="investAmount" type="long"/>
<property column="INVPOL_INVESTABLE_AMOUNT" name="investableAmount" type="long"/>
<property column="INVPOL_TIMEHORIZON" length="30" name="timeHorizon" type="string"/>
<property column="INVPOL_TAXSTATUS" length="1" name="status" type="string"/>
<property column="INVPOL_ASSOCIATED_FEES" name="associatedFee" type="long"/>
<property column="LAST_MODIFIED_DATE" name="lastModifiedDate" type="java.util.Date" update="false" insert="false"/>


<bag name="industryRestriction" table="FBB_INVPOL_INY_BRIDGE" lazy="true" inverse="true" cascade="delete" >
<key column="INVPOL_ID" />
<one-to-many class="com.sp.fbb.businessobject.investpolicy.InvestPolicyIndustryRestriction" outer-join="true"/>
</bag>

<bag name="instrumentRestriction" table="FBB_INVPOL_SIR_BRIDGE" lazy="true" inverse="true" cascade="delete" >
<key column="INVPOL_ID" />
<one-to-many class="com.sp.fbb.businessobject.investpolicy.InvestPolicyInstrumentRestriction" outer-join="true"/>
</bag>
</class>
</hibernate-mapping>

Query:
queryString =
"from InvestPolicy as x left join fetch x.industryRestriction left join fetch x.instrumentRestriction where x.investPolicyID=?";
Query q = session.createQuery(queryString);
q.setParameter(0, investPolicyID);
List result = q.list();

but the application can't initialize the IndustryRestriction list, once I call get the IndustryRestriction List, the following errors displayed:net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session.

The second child list instrumentRestriction is initialized successfully

Can anyone help me to solve this?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 5:03 pm 
Beginner
Beginner

Joined: Fri Aug 29, 2003 12:38 am
Posts: 22
Location: Phoenix, AZ
if you are trying to access a lazy-loaded property after session.close() this will happen. You either need to access the property before ending the session or call Hibernate.initialize(obj.getProperty()) before ending the session to "preload" the lazy reference


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I believe that the fetch option can only be used to eagerly fetch one association per HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 5:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I believe that the fetch option can only be used to eagerly fetch one association per HQL.


Only one collection. You can fetch as many many-to-ones as you like.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 9:20 am 
Newbie

Joined: Mon Oct 06, 2003 2:20 pm
Posts: 10
since I am using tread local for get the hibernate session, does it mean that there is no way to load more than one one-to-many collection using left join fetch? Can Hibernate.initialize(obj.getCollection1()) and Hibernate.initialize(obj.getCollection2()) get two collections at the same time?

If not, does Hibernate going to support it? I think lazy load more than one collections is common usage for hibernate.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
eh? I think you are very confused. What on earth does thread local session have to do with this?


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