This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
1) EJB has a serialized JPA Entity initialized by DI
2) Business delegate in web tier calls the ejb directly and ejb return a DTO
3) Same DTO is returned to JSF Managed bean which consumes the data from this DTO.
Question 1): Are there flip sides of using serialized JPA Entity as DTO? I know it shouldn't be used in the cases when Entity is big enough and client needs just few attributes of it. Passing the whole big object in that case might hurt performance. But in the cases where DTO needs most of the data from single entity, creating one more logic to copy the data from entity to dto does not make sense. Any comments please? Did I get it correct?
Questions 2) BD is client side proxy for business service. Having said this, BD should physically reside in presentation layer (web) but I just got confused by looking at this URL where BD is shown in business layer.
Attempts at answers:
What immediately comes to my mind is that you must make sure that all data has been loaded, even for fields etc that have lazy-loading.
This is to make sure that the data is available even after the business layer has finished executing and released any persistence context used to retrieve data.
One reason for copying the data from a JPA entity object to a DTO, instead of using the JPA entity class in the DTO, may be to prevent developers making the mistake to try to send a JPA entity which contains data that uses lazy-loading and that has not been loaded at the time of sending the DTO to the client.
Why should a Business Delegate reside in the presentation layer?
A Business Delegate is, according to the J2EE Core Patterns book, used to hide communication with remote business services from clients.
Clients may be other business services, residing in the business tier of an application.
Yes, theoretically you can invoke a Business Delegate directly from the presentation layer.
I got confused because of the statement "BD is a client side proxy for business services" and I have personally seen couple of applications in past with my clients where BD & SL both were residing in web utils".
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Passing Serilizable JPA Entity from EJB to Web Tier