Hi,
I am using jooq with hibernate in my project for data persistence.
jooq - for read operations.
hibernate - for saving, deleting, updating data.
Jooq and hibernate have their own independent datasources configured pointing to same underlying database.
1. Is it possible to make the jooq datasource read only- to restrict save, update and delete using jooq?
2. What is the difference in the transaction management feature supported by hibernate and jooq? Is there any transaction management feature supported by hibernate which is not available in jooq?
I work on a large project using both hibernate and jooq.
Hibernate is used when:
* we need to save/update/delete an entity
* fetch entities objects
We use QueryDSL to create custom query to retrieve complex objects graph.
jooq is used when:
* to overcome QueryDSL limitations
* to overcome ORM constraints: reports or complex queries do not fit well in entity based world
A quick strategy I use to choose between hibernate and jooq is:
If I need to present data to the user like a query result, with zero o few business logic on top of it AND I don't need to have an entity to work with I choose for jooq.
If I need an entity I use pure hibernate or QueryDSL.
I usually don't use jooq to fetch data and fill hibernate entity pojo, or when I do that entity is very simple.
We experienced to use jooq also for non trivial entity fetch and mapping the result into entity graph, but we realize that we need too much effort to do that and than we discovered QueryDSL :p
Regarding datasource: I share same datasource between hibernate and jooq. Seems quite reasonable to me use database permission to separate functionalities, not technology framework database access but if you need to do that you can follow Lukas tips.
Regards
Daniele
We use QueryDSL to create custom query to retrieve complex objects graph.
A quick strategy I use to choose between hibernate and jooq is:
If I need to present data to the user like a query result, with zero o few business logic on top of it AND I don't need to have an entity to work with I choose for jooq.
We experienced to use jooq also for non trivial entity fetch and mapping the result into entity graph, but we realize that we need too much effort to do that
You are right, I've abused of "business logic" term :p
Surely you can move any business logic into the query.
For services that I built from scratch, I use only jooq implementing complex query (with a lot of business logic on top of it)
Let me explain a bit more what I mean.
We introduced jooq on an already running system, so we had to maintain and evolve a 100% hibernate software (with a lot performance issues).
Many of the business logic was already built in Java layer: object graph navigation, state machine management, also a pure object filtering!
The problematic scenario was that Java layer use a lot the "transparent" aspect of an orm, and in particular the lazy fetching feature. When we try to replace the hibernate dao (unmaintenable queries using hibernate criteria) with ad hoc optimize jooq query, we faced out that another piece of code used that method to retrieve the same BUT then it navigate a different part of objects graph.
In conclusion,
If you have a lot of Java logic traversing your entities and your code rely heavily on orn lazy fetching, using jooq to replace the native orm behavior is a game over.
If you fetch from db _all_ data you need to perform any business logic you can safely replace orm queries with jooq, but you have to deal with mapping.
In both scenarios jooq support for jpql would be great, but I see technical problems (maybe it requires a new discussion)
If you need a pure relational feature, like report, you have to use jooq.
Regards
Daniele
You are right, I've abused of "business logic" term :p
Surely you can move any business logic into the query.
For services that I built from scratch, I use only jooq implementing complex query (with a lot of business logic on top of it)
In conclusion,
If you have a lot of Java logic traversing your entities and your code rely heavily on orn lazy fetching, using jooq to replace the native orm behavior is a game over.

If you fetch from db _all_ data you need to perform any business logic you can safely replace orm queries with jooq, but you have to deal with mapping.
In both scenarios jooq support for jpql would be great, but I see technical problems (maybe it requires a new discussion)