-->
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: About the use of the lazy=true.
PostPosted: Mon Feb 28, 2005 5:36 pm 
Newbie

Joined: Mon Feb 28, 2005 5:07 pm
Posts: 1
Assume i have an application with, for example, two layers (a user interface layer and a business layer) and i have some functionality that shows me a list of, for example, customers... and by definition each customer has a set of orders mapped as lazy=true.
Initially i only wanna see the list of customers, but if i select one in the list, i wanna see his orders. I get this list from the user interface layer by calling something like:

Code:
List customers = BL.Customers.getAll();

In this context is possible to work with lazy=true for the related orders?.

I wanna show to the user the orders recovered by something like:

    List selectedCustomerOrders = ((Customer)customers.get(someIndex)).getOrders;


Is this possible? Does this force me to open a session in the interface layer, before retrieve the customers List, overload the BL.Customers.getAll() so it can receive it, and keep that session open so the user can check the customers list and, if he need, see the corresponding orders detail??

It doesn´t look good at all, but what's the alternative? Not to use the lazy=true?
doesn´t seem to be very good too...

Other option may be to make another call to the business layer to get (now fully loaded) the selected customer.... or at least with the orders properties loaded...

how can i do this? using more than one mapping per class???
Or doing a dummy access to the property before returning the entity (something like a Count)???

Is there some pattern i should be using and I'm not? (maybe the "do the things well" :))

Any suggestion is welcomed. Thanks!


QuestionerAnswerer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 8:41 pm 
Regular
Regular

Joined: Thu Dec 18, 2003 2:14 am
Posts: 103
Location: Brooklyn, NY
Look in the docs and wiki for patterns.

either:
1) keep the session open until the transaction with the UI is complete, so it can render lazy associations (common web practice)
2) initialize associations before handing them off to the UI
3) detach the object after handing them off, then on a query from the UI reattach the selection to a new session, fill in the associations and return it

It all depends on what you consider a complete "transaction" to be in your app.


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.