<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<!--第一个为oracle的方言配置都一样-->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:数据库名</property>
<property name="connection.username">用户名</property>
<property name="connection.password">密码</property>
<property name="show_sql">true</property> <!--此语句为了再控制台显示对应的SQL语句-->
<mapping resource="com/set/test/Users.hbm.xml"/>
</session-factory>
</hibernate-configuration>
我在用Struts+Spring+Hibernate时遇到了Could not open Hibernate Session for transaction最后我解决了这个问题。我现在把问题贴在了下面!我最终确定是因为数据链接自动关闭,而不是spring和hibernate的问题。
解决办法是:
1.看看数据库的jdbc驱动是否支持重连
注意:mysql的重连autoReconnect参数不能使连接重连
2.寻找支持重连的连接池。
注意:c3p0连接池支持重连重连参数是:
idleConnectionTestPeriod 设置空闲连接测试周期
preferredTestQuery : 设置一查询语句,用于重连测试
testConnectionOnCheckin设置为true
testConnectionOnCheckout设置为true
javax.servlet.ServletException: Could not open Hibernate Session for transactionnested exception is org.hibernate.TransactionException: JDBC begin failed:
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
com.p3g.common.SessionFilter.doFilter(SessionFilter.java:58)
root cause
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transactionnested exception is org.hibernate.TransactionException: JDBC begin failed:
org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:524)
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:322)
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:255)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:102)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/guohelp/archive/2007/05/25/1625236.aspx
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)