Returning Business Objects to View?
All,
I was just in a meeting where two different approaches to returning data to the view were discussed.
In a nutshell, here are the two options presented:
1) The service layer should return the Business Entities entirely (which happen to be Hibernate objects).
2) The service layer should return an object thats specific to the process at hand and contains only the data needed for that process.
We will have multiple clients invoking the service both remote, and local.
My preference is to go with option 2.
What are your thoughts?
Thanks in advance,
KL
[617 byte] By [
Liggya] at [2007-10-2 9:55:07]

If you had not mentioned the words "Hibernate object", I would have been agnostic. However, IMO, these should be considered persistence tier objects. While there is a 'lazy-load view' pattern, there is also much discussion as to whether this is a good idea. For example, if I call a getter on a Hibernate object within the view, it may invoke a complex series of database operations to fetch a graph of dependent child objects.
IMO, it is the responsibility of the controller to ensure that the view has all model data required to render properly.
There is one further point to consider, only tangentially related to your original topic. Hibernate objects, generally, will correspond more strongly to the persistence scheme than the actual ideal OO model you might have designed separately. True, for the vast majority of model->persistence mappings, this will be 1 to 1. However, for the 20% of the system where this is not the case, you really do want to use a full-fledged model object.
So, couple with what, to me, is dangerous--having a view implicitly lazy-load data--with the fact that a HIbernate 'object model' is really more of a 'table-model', I would advise against option #1.
- Saish
Saisha at 2007-7-16 23:59:50 >
