最近用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
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