Spring JPA + JDBC in same transaction - spring

If a transaction is started using Spring's #Transactional, is there any issue using a combination of JPA and JDBC within this transaction?
Meaning, will the transactional handling still work as expected where if an rollback happens, it will rollback all JPA and JDBC changes?
The JPA access would be done through Spring Data repositories and the JDBC access through JdbcTemplate.

No there is no issue.
As both JPA and JDBC simply execute SQL in the same transaction.

Related

Which transaction manger to be used in Spring JPA Eclipselink with JTA enabled

I'm using Spring 4.0, EclipseLink 2.6.3 with JPA 2.0 and IBM Websphere 8.5.5.8 with JTA enabled (Oracle 11g).
As of now my app is configured with WebSphereUowTransactionManager as my server/ container is Websphere like below.
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"></bean>
When I was referring to this link from spring doc's in the 8.9.1. Use of the wrong transaction manager for a specific DataSource section it says
If you are using global transactions, you must use the Spring
org.springframework.transaction.jta.JtaTransactionManager for all your
for all your transactional operations. Otherwise Spring will attempt
to perform local transactions on resources such as container
DataSources.
What does it mean ? Should I shift to org.springframework.transaction.jta.JtaTransactionManager as I'm using Spring #Transactional attributes in my services and DAO's ? Please advice.
UPDATE
As mentioned by #JBNizet its a super class extend by different vendor specific Transaction managers.In that case when should I use org.springframework.orm.jpa.JpaTransactionManager ? How is it different from others ?

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 JTA supported by MONGODB

In my application I need to store some data to the RDBMS DB and some data to the MongoDB in the same transaction and I am using Spring JTA for my RDBMS transactions.
I am new to MongoDB and i am not sure that will this Spring JTA supported by MongoDB. What's the way or api to handle a transaction programmaticaly in MongoDB as MongoDB doesn't support transaction.
As like working with RDBMS and by annotating a method #Transactional, all operation's in method done as a single atomic operations and if an error occur automatic rollback done by Spring JTA but how we can achieve this using MongoDB?
You can use atomic operations or two-phase commit. Also Check this out. This article explains about plugin developed for Mongo that promises not only transactions but also a boosting in performance.

Spring DatasourceTransactionManager not release connection after commit/rollback

I have an Enterprise Application (ear) deployed in this configuration enviroment:
Weblogic 12c (12.1.1) + Oracle RAC 11g (release 2).
Web Module is an MVC application, implemented with Struts 2 and Spring-framework (3.2.2) for core services. Spring JDBC is used for database access with simple JdbcTemplate for single statements and DatasourceTransactionManager for complex ones. I noticed a strange behavior when I enable Weblogic jdbc logs. When I start a new transaction, I can see jdbc info logs about transaction creation, retriving jdbc connection from weblogic datasource pool and setting autocommit property to false value over connection itself. But I can't see transaction releasing connection log, and restoring autocommit flag to true value after commit/rollback invocation.
It's possible that Spring Transaction Manager does not release jdbc connection and does not restore "autocommit" value flag (to true)? After a while I can see within my application some persistent locks on db tables, causing an overall defect of my application and that I would not have depended on the behavior of the transaction manager.
Has anyone noticed a similar behavior?
Is it possible that jdbc connection is not released by the framework and it can compete in multiple transactions (as seen in jdbc log)?
Thanks
Paolo
Since you are using managed DataSource from WebLogic (JNDI?) you have to use managed TransactionManager as well:
<tx:jta-transaction-manager/>
should be enough:
if (weblogicPresent) {
return WEBLOGIC_JTA_TRANSACTION_MANAGER_CLASS_NAME;
}
And it is instead of that DatasourceTransactionManager.

Some people say you can handle any global(XA) transaction with Spring + hibernate, true or not?

Some people say you can handle any global transaction with Spring + hibernate, true or not?
Other people say you also need an application server XA datasource or another XA JTA implementation like atomikos or JbossTS or Bitronix.
Which people are correct?
A)spring + hibernate
B)spring + hibernate + another XA JTA implementation?
Neither Spring nor Hibernate comes with an XA-enabled transaction manager. So you indeed need such a transaction manager in order to have distributed transactions with Spring/Hibernate.
This is explained in the Spring documentation.

Resources