jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex

  • A+
所属分类:Linux教程

1.在使用Tomcat部署一些东西时,你会遇到返回码500,比如下面部署jspgou商城报错

Type Exception Report

Message Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
	org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:544)
	org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
	org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:447)
	org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:277)
	org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
	com.sun.proxy.$Proxy30.getWebsite(Unknown Source)
	com.jspgou.core.web.WebsiteFilter.doFilter(WebsiteFilter.java:35)
	org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:151)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	com.jspgou.common.web.ProcessTimeFilter.doFilter(ProcessTimeFilter.java:31)

jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex
这时候你需要仔细检查一下,有没有和配置文件上面的一一应。
下面用jspgou商城举例:

一、在mysql数据库中创建jspgou数据库(推荐使用此数据库名,否则参照第二条修改对应的数据库链接信息),字符集为utf-8,
二、更改数据库链接,程序包内ROOT\WEB-INF\config\jdbc.properties文件第20行左右
jdbc.url=jdbc:mysql://127.0.0.1:3306/创建好的数据库名?characterEncoding=UTF-8
jdbc.username=登录数据库用户名
jdbc.password=登录密码
三、将压缩包内 DB文件中jspgou.sql文件导入至创建好的jspgou数据库中,如导入中出现执行sql语句过长问题,请修改
[root@localhost ~]# vim /etc/my.cnf
在[mysqld]下面添加如下列:
sql_mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

[root@localhost ~]# cp -r ROOT/ /data/application/tomcat/webapps/
#因为我已经将目录拷贝到Tomcat默认的访问目录下了,所以我们修改的配置文件应该去/data/application/tomcat/webapps/ROOT下面找
[root@localhost ~]# cd /data/application/tomcat/webapps/ROOT/WEB-INF/config/
[root@localhost config]# vim jdbc.properties 

jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex
输入你自己的数据库密码,而且你数据库里面库的名字一定要和jdbc.url里面的保持一致jdbc.url=jdbc:mysql://127.0.0.1:3306/创建好的数据库名?characterEncoding=UTF-8
jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex
修改完后保存退出,并重启相应的服务就可以了。
如果重启服务还是显示500的返回码,那就重启虚拟机

[root@localhost ~]# reboot now         #重启虚拟机
[root@localhost ~]# systemctl stop firewalld                  #关闭防火墙
[root@localhost ~]# setenforce 0                                   #关闭selinux
[root@localhost ~]# systemctl restart mysqld              #重启数据库
[root@localhost ~]# /data/application/tomcat/bin/startup.sh         #启动Tomact服务
Using CATALINA_BASE:   /data/application/tomcat
Using CATALINA_HOME:   /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp
Using JRE_HOME:        /usr/local/java
Using CLASSPATH:       /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
Tomcat started.

jspgou商城部署时报错:Could not open Hibernate Session for transaction; nested exception is org.hibernate.ex

你们的评论和点赞是我写文章的最大动力,蟹蟹。

转载自:https://www.cnblogs.com/yjssjm/p/12659715.html

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: