spring /hibernate/struts 三个框架,在周期性执行操作数据库,发生如下错误,纠结了好久,还是不能解决问题,请各位大侠帮忙!!!!Exception in thread "Timer-1" org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is java.lang.NullPointerException
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at com.huawei.tools.dao.ConnectDBDao$$EnhancerByCGLIB$$da709791.saveObject(<generated>)
at com.huawei.tools.servic.ExecuteRecordServic.saveExecuteRecord(ExecuteRecordServic.java:13)
at com.huawei.tools.autoTestTaskMannager.ConnectClientSocket.createExecuteRecord(ConnectClientSocket.java:293)
at com.huawei.tools.autoTestTaskMannager.TimerAutoTestTask.run(TimerAutoTestTask.java:90)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.slf4j.impl.Log4jLoggerAdapter.isDebugEnabled(Log4jLoggerAdapter.java:194)
at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:247)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:551)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:575)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:583)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:491)
... 13 more我的applicationContext.xml配置是<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id = "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
dependency-check="none">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/tools?autoReconnect=true"/>
<property name="user" value="root"/>
<property name="password" value="7410"/>
<property name="initialPoolSize" value="20" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="60" />
<property name="maxIdleTime" value="3600" />
<property name="idleConnectionTestPeriod" value="360" />
<property name="preferredTestQuery" value="select 1" />
<property name="acquireIncrement" value="5" />
<property name="acquireRetryAttempts" value="50" />
<property name="acquireRetryDelay" value="1000" />
<property name="breakAfterAcquireFailure" value="true" />
<property name="checkoutTimeout" value="20000" />
<property name="autoCommitOnClose" value="false" />
<property name="forceIgnoreUnresolvedTransactions" value="false" />
<property name="unreturnedConnectionTimeout" value="1000" />
<property name="maxStatements" value="0" />
<property name="maxStatementsPerConnection" value="0" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="usesTraditionalReflectiveProxies" value="false" />
<property name="numHelperThreads" value="5" /> </bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/huawei/tools/entity</value>
</list>
</property>
<!-- <property name="mappingResources"> <list> <value> com/huawei/tools/entity/Tooluser.hbm.xml
</value></list> </property> -->
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务的传播属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="delete*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="update*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="get*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="*" propagation="REQUIRED" read-only = "false"/>
</tx:attributes>
</tx:advice>
<!-- 配置事务的切入点 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="allManagerMethod" expression="execution(*
com.huawei.tools.dao.*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod"
advice-ref="txAdvice" /> </aop:config> hibernatesessionNullPointerExceptionslf4j
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at com.huawei.tools.dao.ConnectDBDao$$EnhancerByCGLIB$$da709791.saveObject(<generated>)
at com.huawei.tools.servic.ExecuteRecordServic.saveExecuteRecord(ExecuteRecordServic.java:13)
at com.huawei.tools.autoTestTaskMannager.ConnectClientSocket.createExecuteRecord(ConnectClientSocket.java:293)
at com.huawei.tools.autoTestTaskMannager.TimerAutoTestTask.run(TimerAutoTestTask.java:90)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.slf4j.impl.Log4jLoggerAdapter.isDebugEnabled(Log4jLoggerAdapter.java:194)
at org.hibernate.impl.SessionImpl.<init>(SessionImpl.java:247)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:551)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:575)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:583)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:491)
... 13 more我的applicationContext.xml配置是<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id = "dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
dependency-check="none">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/tools?autoReconnect=true"/>
<property name="user" value="root"/>
<property name="password" value="7410"/>
<property name="initialPoolSize" value="20" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="60" />
<property name="maxIdleTime" value="3600" />
<property name="idleConnectionTestPeriod" value="360" />
<property name="preferredTestQuery" value="select 1" />
<property name="acquireIncrement" value="5" />
<property name="acquireRetryAttempts" value="50" />
<property name="acquireRetryDelay" value="1000" />
<property name="breakAfterAcquireFailure" value="true" />
<property name="checkoutTimeout" value="20000" />
<property name="autoCommitOnClose" value="false" />
<property name="forceIgnoreUnresolvedTransactions" value="false" />
<property name="unreturnedConnectionTimeout" value="1000" />
<property name="maxStatements" value="0" />
<property name="maxStatementsPerConnection" value="0" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="usesTraditionalReflectiveProxies" value="false" />
<property name="numHelperThreads" value="5" /> </bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </props>
</property>
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/huawei/tools/entity</value>
</list>
</property>
<!-- <property name="mappingResources"> <list> <value> com/huawei/tools/entity/Tooluser.hbm.xml
</value></list> </property> -->
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务的传播属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="delete*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="update*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="get*" propagation="REQUIRED" read-only = "false"/>
<tx:method name="*" propagation="REQUIRED" read-only = "false"/>
</tx:attributes>
</tx:advice>
<!-- 配置事务的切入点 -->
<aop:config proxy-target-class="true">
<aop:pointcut id="allManagerMethod" expression="execution(*
com.huawei.tools.dao.*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod"
advice-ref="txAdvice" /> </aop:config> hibernatesessionNullPointerExceptionslf4j
解决方案 »
- java io IoException
- jsp下载问题(急)
- struts+spring+hibernate出现的问题,请高手帮忙看看,谢谢大家了
- 一小问题,顶者有分
- 用application对象能不能从jsp向action传对象?
- 如何获取lookupAllHostAddr的源代码
- 关于编译过的CLASS文件﹐应该放在哪里?
- 小问题,大家请帮帮忙~~谢谢~~有分送的~~
- 谁帮忙把下面的例子改成向数据库中添加一条记录而不是update (SmartUpload 问题)
- servlet 因该放到哪个目录??(Resin平台)
- grails在有数据的表中新增字段,如何为新增字段赋初值?
- jsp生成K线图,编译通过了。为什么图片显示不出来呢?
at org.slf4j.impl.Log4jLoggerAdapter.isDebugEnabled(Log4jLoggerAdapter.java:194)
这里抛异常了,导致无法创建事务,看下你使用的log jar是什么,使用合理的log日志框架