Friday, July 2, 2021

Mapstruct mapper to alliviate workload of implementing jpa relationships

 Context

In a recent project, I use different pojo for the entity and domain models. One of the main properties of this architecture is to allow you to not mix database-related abstractions in the domain layer. You are then free to use mostly the very basic annotations that make JPA so successful.  

I also used a mapper Mapstruct to make it easy to map back and forth between domain and entity pojos with little code. As mapStruct traverses the whole object graph by calling pojos accessors, we can reset as needed database relationship links effortless. 

This is another reason while different models for domain and entities make a lot of sense. I will create a little app demo for this usecase.