I am implementing a Spring boot Web service application and trying to connect it with MySQL database, which is also connected by Laravel (PHP) Application. Following exception is occuring on beginning the transaction:
org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC Connection found! JpaTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single JpaTransactionManager for all transactions on a single DataSource, no matter whether JPA or JDBC access. at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:359) ~[spring-orm-4.3.7.RELEASE.jar:4.3.7.RELEASE] at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.3.7.RELEASE.jar:4.3.7.RELEASE] at com.azampay.core.services.BaseService.startTransaction(BaseService.java:45) ~[classes/:na] at com.azampay.core.services.DelegateServiceImpl.getDelegates(DelegateServiceImpl.java:225) ~[classes/:na]
Application.java In application.java, I am providing my own TransactionManager:
@Bean
@Primary
public PlatformTransactionManager transactionManager() {
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setDataSource(dataSource);
return jpaTransactionManager;
}
and for beginning the transaction:
DefaultTransactionDefinition defaultTransactionDefinition = new DefaultTransactionDefinition();
defaultTransactionDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionStatus status = platformTransactionManager.getTransaction(defaultTransactionDefinition);
Solutions (I have tried)
I have tried to exlude the DataSourceTransactionManagerAutoConfiguration.class in Application.java. Similarly, I made my transactionmanager as a @Primary. But nothing works.
Can anyone help me to solve this? I have already search SO and google but could not find any solution.