I'm a newbie to Hibernate, and have a simple design question for more seasoned Hibernate developers.
I have a set of domain model classes that heavily use lazy loading of associated entities, and I need an advice as to whether there is a way to use these domain model objects across the entire tiers without having to define separate DTOs.
According to section 6.5 (Lazy Initialization) in the Hibernate reference manual, access to the members of the lazily initialized/loaded collection must occur only within the transaction in which the refering entity is retrieved, which means that I can not simply pass the refering entity (or a handle on the collection) to the presentation layer, which would then subsequently access the members of the collection, since presentation layer doesn't (and shouldn't) manage transactions.
This brings me the question - should I really create DTO in the business service layer to copy the states of the persistent objects to some dummy in-memory datastructures before returning them back to the presentation layer? Is there some other way to solve this problem that avoids coping stuff all the time across presentation and business tiers?
Thanks for help.
/Jong
|