or to create a domain layer that is consisted of domain models and talk to JPA entities for database accessing? What are the pros and cons for both approaches ? Thanks!
This does really depend on how you code your domain.
In general (in Java) I prefer create a separate set of JPA annotated DTOs to work with persistence. Such DTOs will match db table and will be used within a custom repository that
This approach make domain models truly decoupled from the db schema so that you can evolve both independently. The cons of this approach is that you have more code to write, but I find such code quite easy and cheap to write an maintain.
Using JPA annotation on entities is a quite common approach, but as your domain model evolves and becomes more complex, my own experience is that you have to face with problems that are far more expensive than the other solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With