I have the following situation in my spring boot application:

I use unidirectional relationship modelling for my database entities, in order to prevent difficulties with a bidirectional approach. (Cascading, Updating both sides etc.) Of course I don't want to expose this structure to the presentation layer, thus my DTOs are compositions over multiple tables. Now I have the following question: How do I properly aggregate this DTOs?

At the moment I have a datacomposition service, which calls the relevant services and builds the DTOs. This service is transactional, because otherwise I could create something in one service, but won't be able to roll it back if something goes wrong in antother one. This is cleanest approach I came up with. Before my controller did this work, but this was a bad idea because of the transaction handling. My Problem with this approach is that this datacomposition service returns DTOs, which I don't like since I belong to the group saying, that the service layer only deals with domain objects. Is this acceptable?

Thank you for your help!

  • the service layer only deals with domain objects. Why?
    – Laiv
    Jun 11 at 10:32
  • @Laiv: This is due to the definition of what a service is. If you look at at from a DDD or Martin Fowler point of view, a service only deals with domain objects
    – msts1906
    Jun 11 at 13:44
  • 2
    @msts1906 Neither DDD nor Martin Fowler are authoritative sources for a definition of the term "service". Jun 11 at 16:30
  • It's true that DDD has an element named service with a particular scope and goal, but this is not incompatible with having more services, at different layers (app layer for example) doing the mapping you need. There's no such a thing as a unique service layer. That's something springbooters developers fail to understand.
    – Laiv
    Jun 13 at 7:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.