Does Jooq integrate with JPA Transactions? - jooq

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:
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?
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?

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.

Related

JOOQ how generate record without connection to database

What does your approach to generating Records during compilation time look like without connection to the database? I use to maven plugin for that but I still need a connection to the database but I don't have one.
jOOQ offers 4 out of the box solutions to generating code without a connection to a live database, including:
JPADatabase if your meta data source of truth is encoded in JPA annotations
XMLDatabase for XML based meta data
DDLDatabase for DDL script based meta data (e.g. Flyway migrations)
LiquibaseDatabase for liquibase migration based meta data
All of the above meta data sources come with their own set of limitations, including lack of support for some vendor specific stuff, but that might not affect you. In simple cases, especially the DDLDatabase can be really useful to achieve quicker turnarounds when generating code.
If vendor specific functionality is a thing in your application, then the official recommendation is to use testcontainers to set up your schema for jOOQ code generation (and integration testing!).

HazelCast - How to call a business service through HazelCast Client

I am using HazelCast to cache data from a database in a Proof Of Concept to a likely customer.
Client layer is in C#. I am using the .Net dll to retrieve data from the HazelCast layer.
My requirement is to execute some business logic steps followed by a transaction. This transaction will insert/update few records in the database.
So, I want to execute a service method which will take an object as input and return another object as output. The method implementation will have the business logic followed by the transaction. The method should return the result of the execution.
I see that I cannot invoke a generic service through the HazelCast client.
Client only provides methods to get data through HazelCast datastructures.
Is there a solution for my requirement?
Thanks for your answers.
s.r.guruprasad
Distributed Executor Service or Entry Processor is what you are looking for but apparently it is not made available for a .NET client.
Solution would be have another webservices layer which can make use of Hazelcast's Java client which supports them.
http://docs.hazelcast.org/docs/3.5/manual/html/distributedcomputing.html

How to integrate vert.x and JOOQ (with Autogenerated DAO and POJO and Connection Pooling)

As I know vert.x is event Based. so I am going to use JOOQ autogenerated DAO from worker verticle.
I wrote a blog post about Vert.x and jOOQ integration. You may find it useful.

Spring Hibernate SessionFactory.getCurrentSession in multithreaded environment

I have written a batch application which spawns multiple threads to read assigned files and save records to database. The architecture uses Spring context and Hibernate.
Transaction is managed by Spring and I am using SessionFactory.getCurrentSession to get a session to perform a save operation for each thread.
Consider that I have a generic DAO that handles get, save, update operations and a facade to hide Hibernate implementation, how can I be assured that two threads when invoking SessionFactory.getCurrentSession() are getting their dedicated Session object to perform DB operations.
I found a post in StackOverflow where someone recommended not to use current_session_context_class=thread when using spring managed transaction. what is the default implementation used by Spring for current_session_context_class property?
Thanks in Advance!
As of Spring 2.0 Spring integrates with hibernate throuhg its own implementation(s) of the CurrentSessionContext interface provided by hibernate.
By default spring sets this to the SpringSessionContext to integrate properly. In general you don't want or need to mess with the current_session_context_class unless you are using JTA (although when using Hibernate 4 with a recent Spring version it should also just work).

Global Transaction Handling in Spring Integration

Its a Spring Integration application.I have a requirement where I need to persist to DB and then post to Queue/Topic. This should be part of a single transaction. I am planning to use the JTATransactionManager. Application Server is Tomcat. Would someone please provide some sample configuration code required for this implementation.
You need a third party stand-alone XA transaction manager such as Atomikos. Tomcat doesn't have one.
You might also consider alternatives to using full-blown 2pc.

Resources