-->
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: Failed to initialize a collectiion
PostPosted: Wed Sep 19, 2007 3:54 pm 
Newbie

Joined: Sun Nov 05, 2006 10:19 am
Posts: 13
Hi,

I'm working on a web application project using NH with ASP.NET 2.0

I'm using NH to load a user from the database in the web application. After I'm loading the user I put the object into http session to be used in other requests. At the beginning of every request I'm attaching the object to the NH session using Lock method. Everything works ok. I even can update the user info in the database using this technique. My problem is when I try to load a collection which is in the relation many - many with a object that is in relation many to one with my user object. I'll give the exactly example:

In the User.hbm.xml I have:

Code:
<many-to-one name="UserType" class="UserType, namespace" insert="false" update="false">
      <column name="userTypeId" not-null="false"/>
</many-to-one>


Then in UserType.hbm.xml I have
Code:
<bag name="Properties" table="UserTypes2Properties" inverse="true" lazy="true" cascade="none">
      <key column="userTypeId" />
      <many-to-many class="Properties, namespace">
        <column name="propertyId" not-null="true"/>
      </many-to-many>
    </bag>


Wehn I try to get the user type using the user from http session (after attaching to nh session) everything goes ok. (user.UserType is ok)....
But when I'm doing user.UserType.Properties I get the error:

Quote:
{"Failed to lazily initialize a collection - no session"}


Any idea how to resolve the problem?

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 7:53 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hi,

I guess locking user.UserType before trying to access the collection should solve your problem.

_________________
Please rate this post if it helped.

X.


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.