1

I'm trying to figure out Jooq 3.17 transaction semantics when used in a Spring Boot application that already uses Hibernate. I read the Jooq docs on this: https://www.jooq.org/doc/latest/manual/sql-execution/transaction-management/, and I think these are the relevant portions for me:

There are essentially five ways how you can handle transactions in Java / SQL:

  • You can issue vendor-specific COMMIT, ROLLBACK and other statements directly in your database.
  • You can call JDBC's Connection.commit(), Connection.rollback() and other methods on your JDBC driver, or use the equivalent methods on your R2DBC driver.
  • You can use third-party transaction management libraries like Spring TX..
  • You can use a JTA-compliant Java EE transaction manager from your container.
  • You use jOOQ's transaction API.

By default, jOOQ ships with the org.jooq.impl.DefaultTransactionProvider, which implements nested transactions using JDBC java.sql.Savepoint. You can, however, implement your own org.jooq.TransactionProvider and supply that to your Configuration to override jOOQ's default behaviour. A simple example implementation using Spring's DataSourceTransactionManager can be seen here:

  1. Does this mean that if I'm using Jooq within a Spring Boot + Hibernate application, I need to implement my own version of the example SpringTransactionProvider? Or am I covered by bullet point 4 - maybe Hibernate provides a JTA-compliant Java EE transaction manager?
  2. Is there Jooq logging I can turn on that will show me when Jooq recognizes transactions starting and stopping? Something along the lines of this: How to log the start and the completion of DB transactions in Hibernate but for Jooq?
Kevin
  • 1,080
  • 3
  • 15
  • 41

1 Answers1

0

Does this mean that if I'm using Jooq within a Spring Boot + Hibernate application, I need to implement my own version of the example SpringTransactionProvider?

Not necessarily. It just means you should provide jOOQ with a transaction aware DataSource of some sort, and not use jOOQ's own transaction API.

Is there Jooq logging I can turn on that will show me when Jooq recognizes transactions starting and stopping?

Unless you use jOOQ's transaction API, jOOQ doesn't really care about your transaction. It just works with your transaction aware JDBC resources, just like when you use JDBC directly. There's no jOOQ magic going on here, and thus, there's no jOOQ transaction logging available, as jOOQ doesn't know anything about such transactions.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • How do I provide jooq with a transaction aware data source? – Kevin Feb 08 '23 at 17:39
  • @Kevin: What have you tried? You're using Spring Boot, no? So Spring Boot already does all you need out of the box. It's Spring Boot's main value proposition. Maybe you have a specific question? Because the generic question is answered by "it already works" – Lukas Eder Feb 09 '23 at 10:17
  • That's great news! I just wanted to validate that Jooq would use the JPA transactions, and didn't know how to do that. The Jooq docs made it sound like I needed to write my own DataSourceTransactionManager to get the integration. I'm glad it's all set up to work in Spring Boot. – Kevin Feb 09 '23 at 19:05
  • @Kevin: That seems to be frequent feedback. I'll think about how the manual can be rephrased to make sure that by default, jOOQ doesn't really care about your transactions and will work with any model. – Lukas Eder Feb 11 '23 at 09:16