Search code examples
javaarchitecturejakarta-eedto

DTO, how to avoid them?


We have a legacy web service architecture. I have now the luxury to use EJBs (EJB 3) for new development and I would like to avoid DTOs as it creates 3 parallel layers. If I send the hibernate objects directly to client, what would become of the relations? Creating a detached object wont solve the issue as the associated objects might already be fetched somewhere else. Serializing such hibernate object will force whole graph to be serailized. What approach (other than DTOs) do you use for complex objects?


Solution

  • For remote access (remote EJBs, Web Services etc.) I actually prefer DTOs. They don't include any (surrogate) primary key, only business keys, and provide the client view, while the entities are private to the service and can be changed as needed.