HibernateException: Couldn't obtain transaction-synchronized Session for current thread

后端 未结 4 1205
无人共我
无人共我 2020-12-01 16:40

I\'m getting the following exception when trying to use my @Service annotated classes:

org.hibernate.HibernateException: Could not obtain transa         


        
4条回答
  •  臣服心动
    2020-12-01 17:27

    Very short answer for this questions id, you just need to use @Transactional with your dao class, mark your configuration class as @EnableTransactionManagement and create a bean

    **@Bean
    public PlatformTransactionManager transactionManager() {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource());
        return transactionManager;
    }**
    

    Here, if you see the code example available in EnableTransactionManagement annotation, it suggest to use DataSourceTransactionManager instead of HibernateTransactionManager.

提交回复
热议问题