We have a domain where 90% of the classes are very simple and can be easily displayed 1: 1 in the database. I am very pleased how Hibernate combined with spring-data-jpa removes a ton of responsibilities for these classes.
The rest of the domain, however, is complex and for a number of reasons I don’t want to directly compare it with the database tables.
I conducted an experiment to implement intermediate beans, which is managed by Hibernate and displays the data from these beans into my domain, and it works well when everything is complex to easy. This approach fails when I have a “lightweight” class managed by Hibernate that references a “complex” class that is displayed in custom Java code and not managed using hibernate.
This is when I realized that I could not find a way to configure Hibernate and connect some ObjectFactory object that would allow me to do such transformations on the fly.
- edit -
What is my question: What is the easiest way to have a domain style in DDD style that has zero database problems in essence when using JPA? In DDD, all database problems are handled by the repository, which typically interacts with the DAO.
Problems with a zero database essentially mean that there are no JPA annotations or mapping configurations in the domain classes. One way to do this is for JPA (or other persistence technologies) to manage TOs that map to domain objects. If I take this route, I must have all of my entities, even the simplest (think address), passing through the display layer.
I would like to use something “lazy”, such as JPA for trivial objects, and be able to mix them with other “manually managed” objects. Currently, I do not know a smart solution that allows me to associate a JPA managed entity with a non-JPA managed entity. I can always get a JPA object and then get a non-JPA object with a second call, but would like to avoid this if possible.
gdanov
source share