wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Which One is a Good Design? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Which One is a Good Design?" Watch "Which One is a Good Design?" New topic
Author

Which One is a Good Design?

Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

Hi folks,

Suppose I have a Hibernate entity like this.


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.

Option 1


Option 2


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
My Blog
 
jQuery in Action, 2nd edition
 
subject: Which One is a Good Design?