would setAutoCommit(false) during quartz job affected by other queries? - spring

I have a quartz job that is wired with spring datasource to perform database partition.
I understand setAutoCommit(false) will start a transaction until rollback or commit are called. However I don't know if the transaction will include other queries from spring webservlet by users access the webpage during the quartz partition, from setAutoCommit(false) until setAutoCommit(true)?
So if any servlet query gets error, this would cause rollback to my whole partition transaction.

Related

Spring Boot DB connection release mode

Is there a way to control database connection release strategy in Spring Boot? Something like Hibernate's ConnectionReleaseMode?
My test code would be rougly following:
INSERT query
HTTP call
UPDATE query
INSERT and UPDATE queries are their own methods in a repository bean (either extending CrudRepository, or as a Mybatis #Mapper). HTTP call is in it's own bean.
Now my service bean is where I experiment with different #Transactional settings as my ultimate goal is to have these three steps executed within a single transaction.
The problem is, the HTTP call can take hundreds of millis and Spring is holding the database connection during that time. This quickly leads to an empty connection pool, while the connections themselves are idle.
I have done the same experiments with default configuration using spring-boot-starter-data-jpa and also using mybatis-spring-boot-starter.
The only thing which got me closer to my goal was setting spring.jpa.open-in-view=false for data-jpa, which would release db connections in case of not using #Transactional at all or with propagation set to NEVER. It doesn't work if it's all wrapped in a transactin though.
I'm feeling like I'm missing some vital part of the transaction concept in Spring. Though the Spring reference docs mentions release mode only in relation to JTA transaction manager + JEE container + Hibernate.
Transactions are bound to a connection/session so you can't release the connection in the middle of a transaction. You have to finish the transaction to close/release the connection. Keep in mind that a transaction could abort at any time, and since the HTTP call is not "part of" the transaction, but just runs while the transaction is in progress, it won't help you to keep the transaction open while the HTTP call is running. I'd suggest you go with one of the following solutions:
Use a circuit breaker to cancel the HTTP call if it hits a timeout to have an upper bound for how long a connection/transaction can be open/held
Move the HTTP call out of the transaction, either before or after the transaction
Use two database transactions
Note that you could use a transactional Job Scheduler to schedule a job in the first TX. The job could then, with at least once semantics, try to invoke the HTTP call and then continue with the second transaction or do some compensation if something fails.

Explicitly joining a JTA transaction requires a JTA transaction issue with jBPM 7 and Spring Boot

We use jBPM 7.41 business application with Oracle database. Under high load, transaction timeouts are detected and arjuna marks them for rollback. Then, jBPM executor thread reuse the same transaction and throws a repetitive exception "No active transaction...". The jBPM is working at the begining but after few minutes of work, there is no active JTA transaction. We use asynchronous executor with a simple command throwing exception, the processes execute normally but as soon as Arjuna Transaction Reaper cancels a transaction, the executor threads will throw the same exception "Explicitly joining a JTA transaction requires a JTA transaction".
We think that the same fix done for JtaTransactionManager in is needed for KieSpringTransactionManager.
We created a ticket here https://issues.redhat.com/browse/JBPM-9450 describing the problem and attached logs and a project to be able to reproduce it.
We tried several options, replacing Narayana with Atomikos and Bitronix, Oracle with PostgreSQL but the issue is the same.
It seems that we’re encountering the same problem described here: https://issues.redhat.com/plugins/servlet/mobile#issue/RHBPMS-4621.
Thank you in advance,
We use:
Spring Boot: 2.2.2.RELEASE
Kie Server: 7.45.0.Final
Narayana: 5.9.0.Final
Logs : https://issues.redhat.com/secure/attachment/12501068/logs.txt
Sample project to reproduce the issue available here: https://issues.redhat.com/secure/attachment/12501190/jbpm-perfs-oracle.zip

Make EhCache part of Transaction

Is it possible to make operations on EhCache make part of Spring's JpaTransactionManager?
During the transaction I'm doing some operations (put/evict) on EhCache and I want them to be committed when transaction succeeds and rollbacked when transaction fails. Just like the regular behavior on a database transaction.
How can I achieve this using Spring and Hibernate?
Do I need a JTA transaction manager for this?

Spring transaction management records are not inserted into db table after transaction is commited

I am using Spring transaction management using Hibernate Transaction Manager. I have declarative transactions configured on a class. Transaction starts and commits. But while commiting its not inserting any records to table. Not able to see any Insert table log message. Is transaction uses some other hibernate session object. How to make it to use session object currently in use.

Websphere Scheduler

Websphere Scheduler is using scheduler datasource XA driver . When task is executed by scheduler it is starting a global transaction, but in our application we are creating a new connection to another database and explicitly commiting the data and closing the connection. This data source configured using non-XA driver datasource. For the application we have also enabled the Accept heuristic hazard (Last participant support extension) .
Now while running the scheudler we are getting the exception DSRA9350E: Operation Connection.commit is not allowed during a global transaction .
Can any one help me out in this
Your task runs in a transaction and probably you call commit in that transaction. So you should call your db operations, commit and close db outside that transaction.
Create bean-managed transaction session bean
#TransactionManagement(TransactionManagementType.BEAN)
and move db and transaction related code into the new bean.

Resources