This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: get rid of DTOs with Kodo and Spring
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Lately it annoyed me more and more to use DTOs/ValueObjects, mostly because using them means creating too much classes with no business meaning at all. These objects are more or less programmer gotchas that will clutter your code in some dangerous way. So i decided to take another approach.
As some of you allready know, i am still using JDO. The only change is that i am using KodoJDO now. Even though JDO2 is not speced out yet (any news on this cruel story?), Solarmetric has a lot of JDO2 features allready in. So in order to avoid DTOs, you can easily rely on detachment. Lets say that you have a persistent user object, instead of copying the persistent object to a DTO before closing the PersistenceManager, you can simply detach the object and use it even after PM closing.
Another add-on feature of Kodo is detachment-on-close. With this, you dont even have to fiddle around with the detachment API, because it will be done automaticly on PM closing. This in combination with Spring and the automatisms regarding PM management (opening/closing/..), a lot of things went its way without too much code to write.
Of course there might be a need to use a DTO here and there, but you can handle a lot of scenarios by just using your domain object in the service layer instead of Transfer Objects.