gpt4 book ai didi

java - 无法打开 Hibernate session 进行事务;嵌套异常是 org.hibernate.exception

转载 作者:行者123 更新时间:2023-11-29 16:02:29 29 4
gpt4 key购买 nike

org.springframework.transaction.CannotCreateTransactionException:无法打开 Hibernate session 进行事务;嵌套异常是 org.hibernate.exception.GenericJDBCException:无法获取 JDBC 连接

我是 Spring 新手,使用 Spring mvc 创建登录页面,我无法将数据库(mysql)连接到应用程序。

我有最新版本的 hibernate 5。 异常(exception)是:

类型异常报告消息请求处理失败;嵌套异常是 org.springframework.transaction.CannotCreateTransactionException: 无法打开 Hibernate Session 进行事务;嵌套异常是 org.hibernate.exception.GenericJDBCException:无法获取 JDBC 连接描述

  <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:component-scan base-package="com.vikram"></context:component-scan>

<!-- database connection pooling -->
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.cj.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/webapplication?useSSL=false" />
<property name="user" value="root" />
<property name="password" value="vikram#123" />

<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxIdleTime" value="30000" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="packagesToScan" value="com.telusko.tusk.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="myTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="myTransactionManager" />

</beans>


enter code here
package com.vikram.webapp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.vikram.dao.Logindao;
import com.vikram.entity.Loginentity;

@Controller
public class IndexController

{
@Autowired
Logindao logindao;

Loginentity loginet;

@RequestMapping("/")
public String home()
{
return "index.jsp";
}

@RequestMapping("/login.htm")
public String login()
{
System.out.println("I am at login");
return "login.jsp";
}

@RequestMapping("/checklogin")
public String collectingloginvalues(@ModelAttribute ("loginet") Loginentity loginet)
{
System.out.println("I am at checkinlogin");
logindao.checklogin(loginet);
return "index.jsp";
}

}

最佳答案

由于您没有提供完整的堆栈跟踪,我可以建议您使用以下解决方案。如果由于连接池问题而出现这种情况,请点击here !答案。尝试一下,它会起作用。

关于java - 无法打开 Hibernate session 进行事务;嵌套异常是 org.hibernate.exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56070945/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com