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

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

    Looking at your log I can instantly tell that your transaction settings are wrongly set. That's because there's no TransactionInterceptor call in your stack trace.

    The TransactionInterceptor is called by your Spring Service proxies when your web controllers call the actual Service methods.

    1. Make sure you use the Spring hibernate4 classes:

      org.springframework.orm.hibernate4.HibernateTransactionManager
      
    2. Don't override @Transactional methods, but use a template patterns instead.

    3. Try using JPATransactionManager instead so you can inject the current EntityManager with the @PersistenceContext annotation instead. This is much more elegant than calling sessionFactory.getCurrentSession() in every DAO method.

提交回复
热议问题