-->
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: Problems with lazy initialization
PostPosted: Thu Feb 16, 2006 5:15 am 
Newbie

Joined: Wed Nov 02, 2005 6:07 am
Posts: 12
I've still got a problem with a lazy initialization which I couldn't solve with the help of other topics on this subject.

In my mapping file I've got a simple set-element:

Code:
<set name="groupTypes" >
  <key update="false">
    <column name="bp_cd"/>
    <column name="bp_ods_cd"/>
    <column name="cust_nb"/>
  </key>
  <one-to-many class="CustomerGroupType" />
</set>


In my DAO-class I've got the following search:

Code:
Session sess = getHibernateTemplate().getSessionFactory().getCurrentSession();
       
        Criteria crit = sess.createCriteria(CustomerAddress.class)
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
            .setFetchMode("groupTypes", FetchMode.JOIN)
            .createAlias("groupTypes", "groupTypes")
            .createAlias("groupTypes.details", "groupTypeDetails")
            .add(Expression.eq("BpCd", customer.getBpCd()))
            .add(Expression.eq("BpOdsCd", customer.getBpOdsCd()))
            .add(Expression.eq("AddrTyCd", "002"))
            .addOrder(Order.asc("CustNm"));

        .........

          List result = crit.list();


Unfortunately I got the error "failed to lazily initialize a collection of role".

I think it's just an understanding problem, but can someone please help me?

The error occurs if I try to get access to groupTypes in my Action-class:

Code:
for (Iterator iter = list.iterator(); iter.hasNext();)
       {
            CustomerAddress e = (CustomerAddress) iter.next();
            e.getGroupTypes() ........
        }


JasDA


Top
 Profile  
 
 Post subject: thought
PostPosted: Thu Feb 16, 2006 2:05 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Please post all your relevant code as suggested by forum post template.
I suspect that you are trying to iterate through that collection when session where the object was created is already closed.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.