-->
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.  [ 1 post ] 
Author Message
 Post subject: Left join fetch not working as expected
PostPosted: Fri Sep 10, 2004 9:36 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
I am trying to eagerly load some collections using a left join fetch and my collections are not being populated.

When I get to my view outside the session, hibernate throws the famous net.sf.hibernate.LazyInitializationException.

I am using hibernate 2.1. My code is as follows:

final StringBuffer query = new StringBuffer();
query.append("select step from ApStepVO step ");
query.append("join step.technologies tech ");
query.append("left join fetch step.subSteps substeps ");
if(req.getAssociatedRequestListing().equals(Globals.YES)){
query.append("left join fetch step.clientAssistance ");
}
query.append("where tech.technologyName = :techName ");
query.append("and step.stepDetail <= :stepDetail ");
query.append("order by step.stepCategory");

HibernateTemplate template = getHibernateTemplate();

List steps = template.executeFind(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException{

Query q = session.createQuery(query.toString());
q.setParameter("techName", Globals.GENERAL_COMPUTER_CONTROLS);
q.setParameter("stepDetail", req.getDetail());

return makeListUnique(q.list());
}
}
);
return steps;

The problem is that sub steps is not initialized and when I get to my view I get the exception.



<?xml version="1.0"?>

<!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.securance.vo.ApStepVO"
table="ap_step"
proxy="com.securance.vo.ApStepVO"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="stepId"
column="ap_step_id"
type="int"
>
<generator class="native">
</generator>
</id>

<property
name="step"
type="java.lang.String"
update="true"
insert="true"
column="ap_step"
/>

<many-to-one
name="stepCategory"
class="com.securance.vo.ApStepCategoryVO"
cascade="none"
outer-join="false"
update="true"
insert="true"
column="ap_step_category_id"
/>

<set
name="clientAssistance"
table="ap_step_client_assistance"
lazy="true"
inverse="false"
cascade="all"
sort="unsorted"
>

<key
column="ap_step_id"
/>

<many-to-many
class="com.securance.vo.ClientRequestAssistanceVO"
column="client_assist_id"
outer-join="true"
/>

</set>

<set
name="technologies"
table="ap_step_technology"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ap_step_id"
/>

<many-to-many
class="com.securance.vo.TechnologyVO"
column="tech_id"
outer-join="auto"
/>

</set>

<property
name="stepDetail"
type="java.lang.Integer"
update="true"
insert="true"
column="ap_detail_level_id"
/>

<set
name="subSteps"
table="ap_sub_step"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="ap_step_id"
/>

<one-to-many
class="com.securance.vo.ApSubStepVO"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ApStepVO.xml
containing the additional properties and place it in your merge dir.
-->

</class>

<query name="findStepsByTechnologyId"><![CDATA[
select step from ApStepVO step join step.technologies techs where techs.technologyId = :techId
]]></query>

</hibernate-mapping>





MySQL 4.1


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

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.