Dozer is a great open source utility which is very good in copying Java Beans back and forth. Dozer heavily leverages the principle of "Convention over Configuration" (CoC) so it works best in case the objects you are copying are identical.
Similar functionality offers Apache's BeanUtils library.
For unknown reasons predominantly in "Enterprise" projects DTOs are used primarily to decouple the service user from the the service realization.
Dozer is often used to efficiently copy the data between JPA entities and DTOs. Automatic object synchronization works best in case both objects hierarchies are identical. Given Dozer's Convention Over Configuration nature each difference in the class structure requires configuration. The more the hierarchies diverge, the less efficient Dozer or BeanUtils becomes.
By keeping both hierarchies identical you have the least effort in copying …but also no decoupling. Both, JPA and DTOs, need to be manually synchronized, otherwise CoC-based frameworks will fail by copying the attributes. You could try to generate the DTOs from the JPA entities but this will result in even less decoupling.
In case Dozer is working well out-of-the-box without any configuration, you probably have to think about your design goals and decisions.
[See also an in-depth discussion in the "Real World Java EE Patterns--Rethinking Best Practices" book (Second Iteration, "Green Book"), page 273 in, chapter "Transfer Object and Data Transfer Object"]
See you at Java EE Workshops at MUC Airport!
airhacks.fm the podcast:
Stay in touch: airhacks.news.