-->
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.  [ 8 posts ] 
Author Message
 Post subject: Failed to lazily initialize a collection
PostPosted: Tue May 16, 2006 9:50 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
I have two table Members and Relations

I m getting this error


"Failed to lazily initialize a collection ", in fact in the code i m using EntityList.Load method but still it is raising the exception. Help needed.


=============================
Mapping of First Table AcctMembers TAble

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="false">
<class name="Hierarchy.Domain.TransactionType.NodeBase, Hierarchy.Domain" table="Hie_TransMembers">

<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="assigned" />
</id>
<discriminator column="NodeType" type="String" />
<property name="TabWidth" column="TabWidth" type="Byte" not-null="false" />
<property name="IsRoot" column="IsRoot" type="Boolean" not-null="false" />
<!--Transaction format mapping-->
<one-to-one name="TransactionFormat" class="Hierarchy.Domain.TransactionType.NodeFormat, Hierarchy.Domain" cascade="all" />
<!--Transaction format mapping-->

<subclass name="Hierarchy.Domain.TransactionType.Node, Hierarchy.Domain" discriminator-value="0" >
<component name="Rollup" class="Hierarchy.Domain.TransactionType.Rollup, Hierarchy.Domain" >
<property name="Name" column="Name" type="String" length="50" not-null="true" />
<property name="LockType" column="SystemLock" type="int" not-null="true" />
<!--<property name="LockType" column="SystemLock" type="Hierarchy.Domain.LockType," not-null="true" />-->
<property name="RollupMap" column="RollupMap" type="String" length="5" not-null="true" />
</component>

<one-to-one name="Child" class="Hierarchy.Domain.TransactionType.NodeRelation, Hierarchy.Domain" />

<bag name="Nodes" table="Hie_TransRelationsN" lazy="true" inverse="true" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" cascade="all-delete-orphan" >
<key column="ParentID" />
<one-to-many class="Hierarchy.Domain.TransactionType.NodeRelation, Hierarchy.Domain" />
</bag>
</subclass>

<subclass name="Hierarchy.Domain.TransactionType.Leaf, Hierarchy.Domain" discriminator-value="1">
<property name="LinkID" column="LinkID" type="Int16" not-null="true" />
<one-to-one name="TransactionType" class="Hierarchy.Domain.TransactionType.TransactionTypeFromInvestranCA, Hierarchy.Domain" />
</subclass>

</class>
</hibernate-mapping>

================
Another Mapping of Relations Table

?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" auto-import="false">
<class name="Hierarchy.Domain.TransactionType.NodeRelation,Hierarchy.Domain" table="Hie_TransRelationsN">

<!--this id column is not there previously which now acts as primary key-->
<id name="ID" column="ID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>

<!--<property name="ChildID" column="ChildID" />-->
<property name="Weight" column="Weight" type="Double" not-null="true" />
<property name="Position" column="Pos" type="Int32" not-null="true" />

<many-to-one name="Self" column="ChildID" class="Hierarchy.Domain.TransactionType.NodeBase, Hierarchy.Domain" />
<many-to-one name="Node" column="ParentID" class="Hierarchy.Domain.TransactionType.NodeBase, Hierarchy.Domain"
access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" />
</class>
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject: Further explanation of my point
PostPosted: Wed May 17, 2006 10:25 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
To further explain my point, the scenario is as under -

I have Tree component which contains nodes, subnodes, leaves. So in Nhibernate i have RootNode which contains Nodes collection and so on . A Node may contain collection of Nodes or Collection of leaves.

I am using Lazy loading, so till I continue to load the nodes collection, it is able to load it, but as soon as I try to load the leaves (for the last level node in the hierarchy), I get the following AssertionFailure.

To load the collection i use

if (!IsInitilaized)
{
children.load() //where children is EntityList
}

For nodes collection it works fine but if it is leaves collection, it fires

"A first chance exception of type 'NHibernate.AssertionFailure' occurred in NHibernate.dll"

When i see the source i found that it seems it calls ForceInitialize Method which raises the AssertionFailure Exception.


Top
 Profile  
 
 Post subject: not able to come up with any solution , i m stuck here
PostPosted: Thu May 18, 2006 7:35 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
My problem has not been answered yet, i stuck with this problem.


Top
 Profile  
 
 Post subject: Re: not able to come up with any solution , i m stuck here
PostPosted: Fri May 26, 2006 5:08 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
pcmedsinge wrote:
My problem has not been answered yet, i stuck with this problem.


Join the club! It seems to me there are a lot of unanswered questions regarding lazy loading.. and this is the bit that causes more problems than anything else!

Personally, I think there are immense bugs in the system!..


Top
 Profile  
 
 Post subject: Re: not able to come up with any solution , i m stuck here
PostPosted: Fri May 26, 2006 5:20 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
pcmedsinge wrote:
My problem has not been answered yet, i stuck with this problem.


Join the club! It seems to me there are a lot of unanswered questions regarding lazy loading.. and this is the bit that causes more problems than anything else!

Personally, I think there are immense bugs in the system!..


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 10:55 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
i don't agree that there are immense bugs in the system. certainly there are a few but by and large this library is very solid. it is most likely that you may not be understanding lazy loading thoroughly. i for one took a bit of time to come to terms with the concept. here are a few things to try:

1) make sure your properties are marked virtual
2) make sure you are using the same session to load the lazy collection that you used to load the original parent object. if not, you have to reattach the object to the current section.
3) i notice that you are using generics. this is an experimental feature that may indeed have bugs. try your code without generics to see if you have any issues with generics.

there are just a few suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 10:50 am 
Newbie

Joined: Tue May 30, 2006 10:02 am
Posts: 1
devonl,

How exactly would you reattach an object and then fetch the additional data? I imagined using session.update to re-attach the object but the only apparent way of fetching additional data would be too use the id to re-fetch the object and eagerly fetch associated objects. If this is the case then why have the step to re-attach?

Thanks

Jeremy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 11:01 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
if I was needed to reattach an object to a session, most of the time I am using session.Lock(myObject, LockMode.None); with this method, the object is completely reattached to the session but tells NH not to reload any data. Since you are expecting that the data of an object may have changed, you will probably have to do a session.Lock(myObject, LockMode.Upgrade) or LockMode.Read. you are right that session.Update() will work too, but i'm not entirely sure how you might be using the feature and they are not the same.

session.Update() sends an UPDATE to the database. this assumes you have updated the object yourself outside of a session and you want to be sure those changes are persisted when reattaching to a new session.

session.Lock() can be configured to attach a detached object back to a new session and check the database (using the <version> property) to see if any updates to the object have happened while it has been detached.

my previous post wasn't meant to offend anyone; i run into the occasional bug or missing feature, but by-and-large i feel this library is the best thing .NET has going for it.

-devon


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