Working with Spring Data JPA, Hibernate and multiple transaction manager: No bean named 'transactionManager' is defined Working with Spring Data JPA, Hibernate and multiple transaction manager: No bean named 'transactionManager' is defined spring spring

Working with Spring Data JPA, Hibernate and multiple transaction manager: No bean named 'transactionManager' is defined


Looks like your someOtherMethod calls any other @Transactional component (some class with save method). And I think it has @Transactinal() (empty) annotation (which uses default bean named transactionManager).

You may see 2 TransactionInterceptor positions in stacktrace. Please provide some details about it.


I suspect that you just need to ensure that your repositories use the correctly named transaction manager in your @EnableJpaRepositories annotation.

i.e.

@Configuration@EnableTransactionManagement@EnableJpaRepositories(        entityManagerFactoryRef = "fooEntityManagerFactory",         transactionManagerRef = "fooTransactionManager",        basePackages = {"com.sctrcd.multidsdemo.integration.repositories.foo"})public class FooConfig {    //...}

It took me a while to figure out the details, so I have just provided a fuller explanation of how to configure Spring Data JPA repositories to work with multiple datasources here:

Multiple jpa:repositories in xml config, how to configure with @EnableJPARepositories using Spring java config?

And a full project demonstrating it here:

https://github.com/gratiartis/multids-demo


Actually, there is a way to use named TransactionManager with Spring Data JPA.This works for me:

<bean id="myTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">    <property name="entityManagerFactory" ref="myEntityManagerFactory" /></bean><tx:annotation-driven transaction-manager="myTransactionManager"/><jpa:repositories base-package="com.xxx.yyy" entity-manager-factory-ref="myEntityManagerFactory" transaction-manager-ref="myTransactionManager"></jpa:repositories>