DTO or Domain Model Object in the View Layer?

Posted by smayers81 on Stack Overflow See other posts from Stack Overflow or by smayers81
Published on 2010-04-21T03:14:10Z Indexed on 2010/04/21 3:23 UTC
Read the original article Hit count: 449

I know this is probably an age-old question, but what is the better practice? Using a domain model object throughout all layers of your application, and even binding values directly to them on the JSP (I'm using JSF). Or convert a domain model object into a DTO in the DAO or Service layer and send a lightweight DTO to the presentation layer.

I have been told it makes no sense to use DTOs because changes to the database will result in changes to all your DTOs whereas using Model Objects everywhere will just require changes to the affected model object. However, the ease of use and the lightweight nature of DTOs seems to outweigh that.

I should note that my app uses Hibernate Model Objects AND uses its own custom-created model objects (meaning not bound to any DB session, always detached). Is either of the above scenarios more beneficial to a strict Model Object pattern? Using Hibernate has been a huge PITA with regards to things like Lazy Initialization Exceptions.

© Stack Overflow or respective owner

Related posts about dto

Related posts about data-transfer-objects