We have two architecture definitions:
- A Spring service Bean can only comunicate with its own repository or other services beans;
- A database model object cannot be exposed outside the service bean, it must be mapped to a DTO.
So here’s my scenarium:
I receive a post request with all the information that needs to be persisted, plus ids (primary keys) to its relationships. Since I fetch the relatioships data from other services I get a DTO instead of a model and when I convert back the DTOs into models to be persisted with my primary object those objects are “almost in a dettached state”. I mean, the original objects are in the persistence context since we are in a Transactional method, but I am actually using new mapped objects and thus I get the exception stating that I’m trying to persist dettached objects.
Given my scenario, is there a workaround?