org.hibernate.HibernateException: 没有配置 CurrentSessionContext!弹簧靴

时间:2021-06-18 13:30:16

标签: spring spring-boot hibernate

application.properties

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp

spring.datasource.url=jdbc:mysql://localhost:3306/db_service
spring.datasource.username=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# DDL generation
spring.jpa.generate-ddl=true

我使用了 opensession() 而不是 getCurrentSession() 并且它对我有用,因为我不想在每个事务中打开会话,所以这不能解决问题

1 个答案:

答案 0 :(得分:0)

您必须配置上下文以用于“当前会话”,您可以在文档中阅读:https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#architecture-current-session