Can JPA / Hibernate be combined with other persistences like jOOQ

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.

+7
source share
2 answers

You can combine JPA and JOOQ . JPA / Hibernate is great for writing data:

  • all entity columns are included in INSERT / UPDATE, so you do not need to change save routines when adding new columns
  • extended support for implicit / explicit optimistic / pessimistic blocking
  • support for optimized identifier generators (pooled-lo optimizer)
  • transactional write cache to reduce lock contention (even in MVCC databases)
  • JDBC sample is in only one configuration

SQL and jOOQ are great for reading data, especially when you want to go beyond the abstraction of the SQL-92 JPA dialect. With your own queries (and the secure jOOQ type), you can take advantage of all the features that your database can offer:

  • Window functions
  • PIVOT
  • Derived tables
  • Common table expressions and recursive queries
  • Merge
  • Mass INSERTS / UPDATES

In the end, you are likely to need both JPA and your own queries, so jOOQ is a great choice to get most of your current database, while still providing compile-time security guarantees.

Read more in this free chapter of High-Performance Java Persistence .

+3
source

you can map classes that do not have a 1: 1 representation in the database, it just works more in collation. If you want pure POJOs, use xibernates xml mappings. The most complex database schemas can be matched, and they already have a lot of questions about SO. Submit a question for each class and related database tables / views / functions and we will find the answers.

0
source

All Articles