ssh项目改造上spring-boot时hibernate迁移报错

匿名 (未验证) 提交于 2019-12-02 23:26:52

异常值

spring-boot中设置了 current_session_context_class=thread 运行起来会报错

org.hibernate.HibernateException:      Could not obtain transaction-synchronized Session for current thre 
org.hibernate.HibernateException:      createSQLQuery is not valid without active transaction 

解决办法

修改pom.xml 文件,指定hibernate版本

		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core --> 		<dependency> 			<groupId>org.hibernate</groupId> 			<artifactId>hibernate-core</artifactId> 			<version>4.3.11.Final</version> 			<exclusions> 				<exclusion> 					<artifactId>jboss-logging</artifactId> 					<groupId>org.jboss.logging</groupId> 				</exclusion> 				<exclusion> 					<artifactId>hibernate-jpa-2.0-api</artifactId> 					<groupId>org.hibernate.javax.persistence</groupId> 				</exclusion> 				<exclusion> 					<artifactId>jboss-transaction-api_1.1_spec</artifactId> 					<groupId>org.jboss.spec.javax.transaction</groupId> 				</exclusion> 			</exclusions> 		</dependency>   		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache --> 		<dependency> 			<groupId>org.hibernate</groupId> 			<artifactId>hibernate-ehcache</artifactId> 			<version>4.3.11.Final</version> 		</dependency>   		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-c3p0 --> 		<dependency> 			<groupId>org.hibernate</groupId> 			<artifactId>hibernate-c3p0</artifactId> 			<version>4.3.11.Final</version> 		</dependency>  		<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager --> 		<dependency> 			<groupId>org.hibernate</groupId> 			<artifactId>hibernate-entitymanager</artifactId> 			<version>4.3.11.Final</version> 		</dependency> 		<dependency> 			<groupId>org.springframework.boot</groupId> 			<artifactId>spring-boot-starter-data-jpa</artifactId>             <version>1.4.0.RELEASE</version> 			<exclusions> 				<exclusion> 					<groupId>org.hibernate</groupId> 					<artifactId>hibernate-core</artifactId> 				</exclusion> 			</exclusions>         </dependency> 
文章来源: https://blog.csdn.net/hzwy23/article/details/88843864
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!