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.
And I have simple architecture like this (for simplicity, I've removed all the interfaces, etc)
View Layer -> Service Layer -> DAO Layer
This is my DAO layer code.
This is my service layer code.
The view layer will eventually invoke the server layer, e.g. the UserPage will call the UserService class.
My question is, which one is a better design, option 1 (to pass a Hibernate entity to a view layer) or option 2 (to create another POJO that gets all the information from the Hibernate entity and pass it to a view layer)?
In my opinion, option 2 violates the DRY principle since we need to create another POJO which is basically just a subset of the Hibernate entity, but option 1 seems to expose too much information to the view layer, i.e. the database specific properties, e.g. id, createdBy, lastModifiedBy, createdBy, createdDate.
What do you guys think?
SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4