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.  [ 1 post ] 
Author Message
 Post subject: Lazy loading for entity collection obejct
PostPosted: Thu Nov 05, 2009 8:17 am 
Newbie

Joined: Sat Oct 31, 2009 9:38 am
Posts: 5
Hi,

I have a entity object "customer" and it have "CustomerOrders" as list of the customer orders.
following is my relation in mapping file. I have 14 customer in my database.It is returns all the customer orders with customer object.
Code:
<set name="CustomerOrders" lazy="false" >
      <key column="customerId"/>
      <one-to-many class="Orders" />
    </set>

it is not a good way to get the data. It is loading ""CustomerOrders" collection for all the customers. It is decreasing the application performance. So i set the "lazy=true". It is loading all the customer objects first and when we hit the "CustomerOrders" then it initializing the orders collection. It is also working fine. in single layer architecture.

My code is to get the data using session is ...
Code:
Dim criteria As ICriteria = Session.GetISession().CreateCriteria(GetType(T)).SetMaxResults(maxResults)
                result = criteria.List(Of T)()

My problem is my application have different layers. Nhibernate data fetching is in one layer and UI is in seperate layer. When i expand the "CustomerOrders" for a customer in the "datalayer" it is loading the data and working file(in debug mode). The same data is returned to the UI layer and i expand 2nd customer object to see the "CustomerOrders" , it is showing an error message "could not initialize a collection: ".The collection is initializing when i hit the orders in the data layer but the problem with n-tire architecture.

To reduce this problem i added another attribute "fetch=join" in <set> tag.Now it is returns 19 customer object with some duplicate customer object(5 objects are duplicate objects).But the "CustomerOrders" list is loading with lazy. some customers have 2 orders,some have 3 orders and some have empty orders. Every thing is working fine when i add the "fetch=join" attribute.

I have some doubts on this lazy loading. Please help me.
My queries are ....
Q) How can we get the data in UI layer with lazy loading?
Q) How can i avoid duplicate values if i add "fetch=join" in <set> tag?

Regards,
Kiran


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.