-->
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.  [ 4 posts ] 
Author Message
 Post subject: Lazy Loading problem
PostPosted: Tue Mar 14, 2006 5:57 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi folks,

I have a class Client which have a collection (IList) of Order.
The Order class have a collection of OrderItem.

In my Client mapping file (part of it):

<bag name="Orders" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="IdClient" />
<one-to-many class="AcombaTestAppDomainModel.Order, AcombaTestAppDomainModel" />
</bag>


my Order mapping file (part of it):

<many-to-one
name="Client"
column="IdClient"
class="AcombaTestAppDomainModel.Client, AcombaTestAppDomainModel"
not-null="true" />

<bag name="OrderItems" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="IdOrder" />
<one-to-many class="AcombaTestAppDomainModel.OrderItem, AcombaTestAppDomainModel" />
</bag>


my OrderItem mapping file (part of it):

<many-to-one
name="Order"
column="IdOrder"
class="AcombaTestAppDomainModel.Order, AcombaTestAppDomainModel"
not-null="true" />


Now, when I get my Client object, not closing my session

I loop through each order to display it to the screen. It works fine.
Then I try to loop through each order, and loop through each OrderItem of the Order, and I get a LazyInitializationException. I can't even do Client.Orders[0].OrderItems.Count ..

Any help would be GREATLY appreciated!

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 6:08 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
If I set both relation to Lazy="False"

I get the following error:
NHibernate.PropertyAccessException was caught
Message="The type AcombaTestAppDomainModel.Client can not be assigned to a property of type AcombaTestAppDomainModel.CatalogItem setter of AcombaTestAppDomainModel.OrderItem.CatalogItem"
Source="NHibernate"
StackTrace:
at NHibernate.Property.BasicSetter.Set(Object target, Object value)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object[] ids, IType[] types)
at NHibernate.Loader.Loader.LoadCollection(ISessionImplementor session, Object id, IType type)
at NHibernate.Loader.OneToManyLoader.Initialize(Object id, ISessionImplementor session)
at NHibernate.Collection.AbstractCollectionPersister.Initialize(Object key, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.InitializeCollection(PersistentCollection collection, Boolean writing)
at NHibernate.Collection.PersistentCollection.ForceInitialization()
at NHibernate.Impl.SessionImpl.InitializeNonLazyCollections()
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id)
at AcombaTestRepositories.ClientRepository.GetClientById(Int64 id) in C:\Documents and Settings\mbittner\My Documents\Visual Studio 2005\Projects\Com.Progmatik.Accounting\AcombaTestRepositories\ClientRepository.cs:line 25


Top
 Profile  
 
 Post subject: i caught in the similar problem, Have u got the solution ?
PostPosted: Tue May 16, 2006 10:12 am 
Beginner
Beginner

Joined: Tue Feb 28, 2006 3:16 am
Posts: 28
Hi

Let me know if u got any solution for this. In my code i m explicitely loading the collection using Load() method but still it is not working.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:07 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you've got an error in your class file. please post entire class file and mapping file for all three objects.

-devon


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