This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Which One is a Good Design?" Watch "Which One is a Good Design?" New topic

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
It is sorta covered in the JavaRanch Style Guide.
subject: Which One is a Good Design?
Similar Threads
Auto Generator in composite key
Getting only required value when we use event.geetOldState()
Error while trying to get data from Master-Detail tables
Inserting into table with Hibernate question
Hibernate mapping