Could not obtain transaction-synchronized Session for current thread

Could not obtain transaction-synchronized Session for current thread,第1张

最近用springboot,spring-boot-starter-data-jpa(jpa包含了hibernate)配置一个框架遇到很多问题:

1,错误:

Could not obtain transaction-synchronized Session for current thread

解决方法:

在DAO实现层添加:

@Transactional
@EnableTransactionManagement

sessionFactory.getCurrentSession();//必须在这类中加上特性标签 @Transactional @EnableTransactionManagement

参考别人的:Spring Hibernate - Could not obtain transaction-synchronized Session for current thread - Stack Overflow

2,错误:

org.springframework.orm.hibernate5. HibernateSystemException: Could not obtain transaction-synchronized Session for current thread; nested exception is org.hibernate.HibernateException:

解决方法(jpa和):

在application.properties文件添加:

spring.jpa.open-in-view=false

参考别人:java - ClassCastException: org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder - Stack Overflow

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/723203.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存