aspose file tools*
The moose likes Object Relational Mapping and the fly likes Design issue (POJO and DTO/VO) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Design issue (POJO and DTO/VO)" Watch "Design issue (POJO and DTO/VO)" New topic
Author

Design issue (POJO and DTO/VO)

Manju Singh
Greenhorn

Joined: Feb 23, 2005
Posts: 27
I am using struts -> Java Object (business Tier, e.g. Spring) -> Hibernate.

General practice for sendnig data to DAO is through DTO/VO for coarse grain data transfer. With hibernate we have POJO which is same as DTO. Is it good practice to use POJO for data transfer from presentation tier to Hibernate DAO, that means web tier will instantiate the POJO class, populate the POJO object and send it to DAO for persistence.
Or, shall we create separate DTO and separate POJO class ???
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

Basically, the DTO pattern arised because we couldn't serialize Entity Beans, but with Hibernate and Detached objects, you no longer really need DTOs, you can transfer the persistent objects, you can create new instances (transient instances) on the client, attach it to a Hibernate Session and then save it to the database, Hibernate will see it is transient and correctly insert it into the database.

If you had persistent POJOs and seperate DTOs, well now you would have to write extra code to take the values from the DTO and put them into a POJO, kind of extra work for nothing in my mind.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Depends on the nature of your useage. If your POJOs contain only getters and setters then by all means bring them directly out of your store, but sometimes POJOs have real work to do and in this case it can be difficult to bring directly from the store. Sometimes POJOs dont expose their internal data through getters and setters and in this case how do you store them without adding new methods just for storage?

Besides, if all it has is getters/setters it IS a DTO.
Manju Singh
Greenhorn

Joined: Feb 23, 2005
Posts: 27
Thanks for your reply.

Atleast, I got the clear picture of this. And, decided to go ahead with the mixture of POJO and VO depending on the reqmt.
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
but beware of code duplication.
for maintenance it could be quite messy if you have to keep your model-design up to date in two implemented data-models (hibernate pojos + dto).


aldana software engineering blog & .more
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Originally posted by manuel aldana:
but beware of code duplication.
for maintenance it could be quite messy if you have to keep your model-design up to date in two implemented data-models (hibernate pojos + dto).


How would that scenario come about?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design issue (POJO and DTO/VO)