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

后端 未结 4 1207
无人共我
无人共我 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:03

    @Bean
    @Autowired
    public HibernateTransactionManager transactionManager(SessionFactory sessionFactory)
    { 
        HibernateTransactionManager htm = new HibernateTransactionManager();
        htm.setTransactionSynchronization(HibernateTransactionManager.SYNCHRONIZATION_ALWAYS);
        htm.setDataSource(dataSource());
        htm.setSessionFactory(sessionFactory);
        return htm;
    }
    
        You just need to add
        -------------------------------
        htm.setTransactionSynchronization(HibernateTransactionManager.SYNCHRONIZATION_ALWAYS);
        -------------------------------
        I used dependencies 
        -----------------------------------
    
        org.hibernate
        hibernate-core
        5.2.2.Final
    
    
        org.springframework
        spring-web
        5.0.1.RELEASE
    
    

提交回复
热议问题