-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to NOT use Lazy loading??
PostPosted: Wed Nov 08, 2006 9:01 am 
Newbie

Joined: Fri Nov 03, 2006 4:09 am
Posts: 4
Hello,

[b]SHORT DESCRIPTION[/b]
I try to load directly into a property a class instance of a refrenced (many-to-one) class. I use [b]lazy="false"[/b] in the class section. This didn't work so I includeded [b]fetch="join"[/b] in the [b]many-to-one[/b] part. Still NHibernate uses lazy loading. How to stop this behaviour? I want to load the referenced object. Does somebody see a mistake or have a tip on how to solve this unwanted behaviour?

[b]DESCRIPTION[/b]
My project consists of two classes(A.cs and B.cs) and each one has a mapping file (A.hbm.xml & B.hbm.xml). Class A has a property like:
[b]
public virtual B A_B
{
set { this._A_B = value; }
get { return this._A_B; }
}
[/b]
In the mapping file A.hbm.xml I have this section:

[b]<many-to-one name="verpakItem class = "Fruitmasters.Data.VerpakItem" column="verpak_id" not-null="true"/>[/b]

1) The 'class' parts in mappingfiles A.hbm.xml & B.hbm.xml include property [b]lazy="false"[/b]

[b]PROBLEM:[/b]
The property A_B (refrenced class B) is still lazy loaded??
I tried adding [b]fetch="join"[/b]

When I look into an instance of class A I continu to see a proxyclass reference for property A_B. NHibernate continus to load A and resulting A_B lazy.

[b]QUESTION[/b]
How to force a direct load of instance of object B in propertyy A_B of class A?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 9:12 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It should work. Can you show the logs for the retrieval operation?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 09, 2006 11:18 am 
Newbie

Joined: Fri Nov 03, 2006 4:09 am
Posts: 4
Hello Sergey and others,

You were right Sergey something else was wrong and caused strange, ondocumented, behaviuor of NHibernate (for framework 2.x). After creating my mapping-files and classes I started using them. At first I received a lot of mapping errors. When there weren't any mapping errors I concluded that the mapping-files were correct. THIS was my mistake.

1) I tested with data that caused mapping problems;
2) Corrected the mapping/class errors;
3) Started working with (2) -> everything fine;
4) Started using more data -> new mapping errors concealed as strange NHibernate messages
5) Flead through the mapping-files/classes -> found some extra errors -> corrected them

6) Suddenly lazy loading worked as you expected!! Thank you Sergey for your tip!

Stefan


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