Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple transaction managers annotation configuration
    primarykey
    data
    text
    <p>I have two transaction managers configured in annotation-based configuration class:</p> <pre><code>@Configuration @EnableTransactionManagement public class DBConfig implements TransactionManagementConfigurer { //... @Override public PlatformTransactionManager annotationDrivenTransactionManager() { return defTransactionManager(); } @Bean @Qualifier("defSessionFactory") public LocalSessionFactoryBean defSessionFactory() { LocalSessionFactoryBean sfb = new LocalSessionFactoryBean(); sfb.setDataSource(defDataSource()); Properties props = new Properties(); //... sfb.setHibernateProperties(props); sfb.setPackagesToScan("my.package"); return sfb; } @Bean @Qualifier("defTransactionManager") public PlatformTransactionManager defTransactionManager() { return new HibernateTransactionManager(defSessionFactory().getObject()); } @Bean @Qualifier("secondSessionFactory") public LocalSessionFactoryBean secondSessionFactory() { LocalSessionFactoryBean sfb = new LocalSessionFactoryBean(); sfb.setDataSource(secondDataSource()); Properties props = new Properties(); //... sfb.setHibernateProperties(props); sfb.setPackagesToScan("my.package.subpackage"); return sfb; } @Bean @Qualifier("secondTM") public PlatformTransactionManager secondTransactionManager() { return new HibernateTransactionManager(secondSessionFactory().getObject()); } } </code></pre> <p>My intention is use annotation transactions with two transaction managers. Methonds annotated like this </p> <pre><code>@Transactional public void method() {} </code></pre> <p>should be handled by defTransactionManager</p> <p>And methods annotated like this</p> <pre><code>@Transactional("secondTM") public void anotherMethod() {} </code></pre> <p>by secondTransactionManager</p> <p>defTransactionManager works fine but when it comes to anotherMethod() I get:</p> <pre><code>org.hibernate.HibernateException: No Session found for current thread </code></pre> <p>When I use programmatic transaction management for anotherMethod (autowire secondSessionFactory, use TransactionTemplate) everything works fine.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload