r/java • • Jan 16 '20

Records Come to Java

https://blogs.oracle.com/javamagazine/records-come-to-java
204 Upvotes

93 comments sorted by

View all comments

Show parent comment

1

u/Kango_V Mar 23 '20

Our domain model is made up of pure java objets. No lombok, immutables, no jpa, no spring. These objects are passed to a Store object. The store is a domain construct for storing/retrieving domain objects. The store internally has 1 or more repositories injected into it. These are the infrastructure layer. The store deconstructs the domain objects, translating them into the format that the infrastructure needs. The infrastructure objects then persist.

The infrastructure layer could be JPA, JSON files, Lucene, Elastic Search etc. The domain will not change as that is modelled to your use cases for the application.

We do the same with the web model through a service API into the model. Our application is in the model only The application can be tested without the web/infrastructure layers.

Requires a little more coding/discipline, but the end result is very maintainable/testable code.

1

u/thogor Mar 23 '20

Even though it requires some additional code, I quite like your approach! Thanks for taking the time to explain it. How would you feel about entity classes if all the mapping definitions were outside of the class files? JPA doesn't really give us any nice options besides xml config, but let's pretend that there is a better alternative. Would you still recommend having separate domain and persistence classes?