I am implementing a spring boot microservice using Clean Architecture. I have a multi module java app, with domain, application and infrastructure.
Domain and Application modules do not know anything about Spring framework. In domain I have my models, exceptions etc.. but this is pure java. In application I have my input and output ports and also my Application service which implements those ports.
In infrastructure I have everything you can imagine a spring boot application would need. My problem is that I have my DomainModel and in infrastructure I have created a DomainJpaEntity class which basically is a twin of my domain model but here I can use the needed annotations to map the table to the entity. Everytime I need to transform(map) the entity to my domain model in order to use the ports ( because they always expect the domain model as an argument)
Recently I stumbled upon another issue. I have a DomainModelJpaAdapter which basically implements the PersistenceOutputPort with Jpa. I want to test one method where I want to check for Optimistic Locking of my entity, but since the adapter is always returning the domain model, I do not have the "Version" field in my domain model... and it feels wrong to also have it there..
Has anyone ever implemented Clean Architecture this way? Or you also allow the application layer have information about Spring?
Yes I did, the first time. It was overkill. And I did store the version inside the domain model.
Now that’s what I do. For example, my JPA entities are also my domain models. This avoids the tedious and bug-prone conversions. The goal of an ORM is already to abstract the persistent layer. No need to add an abstraction on top of that.