JDBC, Transactions, Spring Data JPA
July 30, 2021

M03 Q22 Are you able to participate in a given transaction in Spring while working with JPA?

Yes, JPA in Spring uses JpaTransactionManager, which supports cases when DataSource is used directly, so it allows mixing JPA and JDBC code under one transaction.

When using Spring Framework on Java EE platform, it is possible to reuse existing transactions as well by using JtaTransactionManager, which will delegate transaction management to Java EE container.

For example, you have two DAO classes: JpaEmplyeeDao and JdbcEmployeeDao

And you have EmployeeService which uses JpaEmployeeDao and JdbcEmployeeDao.