升级到hibernate 4:org.hibernate.TransactionException:无法提交JDBC连接

时间:2014-09-01 08:12:28

标签: hibernate quartz-scheduler jta

我正在尝试将项目从Hibernate 3.5升级到Hibernate 4.2,但现在我在spring上下文初始化期间得到了以下异常(我们使用的是Spring 3.2.2)。

您可以在下面找到我们的配置。

有关异常原因的任何想法吗? 将休眠版本恢复为3.5,异常消失。

...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CLUSTERED_Scheduler' defined in class path resource [etc/scheduling/quartz-scheduling-context.xml]: Invocation of init method failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: commit failed; nested exception is org.hibernate.TransactionException: commit failed
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
    ...
Caused by: org.springframework.orm.hibernate3.HibernateSystemException: commit failed; nested exception is org.hibernate.TransactionException: commit failed
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:690)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:105)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
    at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:328)
    at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:511)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
    ... 36 more
Caused by: org.hibernate.TransactionException: commit failed
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:185)
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:513)
    ... 42 more
Caused by: org.hibernate.TransactionException: unable to commit against JDBC connection
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:116)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:178)
    ... 44 more
Caused by: java.sql.SQLException: Connection is closed.
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(PoolingDataSource.java:185)
    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.commit(PoolingDataSource.java:210)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doCommit(JdbcTransaction.java:112)
    ... 45 more

在Quartz调度程序bean初始化期间发生异常。这是我们的配置:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
    name="CLUSTERED_Scheduler" lazy-init="true">

    <property name="dataSource" ref="dataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="overwriteExistingJobs" value="false" />
    ...
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    p:dataSource-ref="dataSource" 
    p:persistenceXmlLocation="classpath:persistence.xml">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
            p:database="${jpa.database}" 
            p:showSql="${jpa.showSql}"
            p:generateDdl="${jpa.generateDdl}"
            p:databasePlatform="${jpa.databasePlatform}" />
    </property>
</bean>

<bean id="transactionManager" name="npp"
    class="org.springframework.orm.jpa.JpaTransactionManager"
    p:entityManagerFactory-ref="entityManagerFactory"
    p:dataSource-ref="nppDataSource"
/>

这是persistence.xml内容:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="punit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>...</class>
        ...
        <properties>
            <property name="hibernate.ejb.interceptor"
                value="my.Interceptor" />
        </properties>
    </persistence-unit>
</persistence>

1 个答案:

答案 0 :(得分:1)

这是Spring中的一个错误:SPR-10395 - 您应该将其更新为版本3.2.3 +