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