AnsweredAssumed Answered

Transaction problem within spring config / hibernate

Question asked by cthurier on Jun 7, 2013
Latest reply on Jun 10, 2013 by trademak
Hello,

I'm facing a problem with my spring configuration. My processEngine bean can't be created.
Instead, following exception is throwed :

Caused by: org.hibernate.TransactionException: commit failed

Caused by: org.h2.jdbc.JdbcSQLException: The object is already closed [90007-167]

My config is :


<?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:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:util="http://www.springframework.org/schema/util"

   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

   <!– config –>
   <context:annotation-config />

   <!– <import resource="classpath:spring-dcontract-core-context.xml" />–>
   
   <bean
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
      id="properties">
      <property name="locations">
         <list>
            <value>classpath:properties/database.properties</value>
         </list>
      </property>
      <property name="ignoreUnresolvablePlaceholders" value="true" />
   </bean>   
   
   <bean
      class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

   <bean id="coreJpaAdapter"
      class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
      <property name="showSql" value="${jpa.showSql}" />
      <property name="databasePlatform" value="${jpa.dialect}" />
      <property name="generateDdl" value="${jpa.generateDdl}" />
   </bean>

   <bean id="dContractDataSource"
      class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
      <property name="driverClass" value="${dcontract.database.driverClass}" />
      <property name="url" value="${dcontract.database.url}" />
      <property name="username" value="${dcontract.database.username}" />
      <property name="password" value="${dcontract.database.password}" />
   </bean>

   <bean id="dContractEntityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dContractDataSource" />
      <property name="jpaVendorAdapter" ref="coreJpaAdapter" />
      <property name="persistenceUnitName" value="digital-contract-unit" />
      <property name="packagesToScan" value="net.domain.entity" />
   </bean>

   <bean id="dContractTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="dContractEntityManagerFactory" />
   </bean>

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

<!– activiti –>
   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!–       <property name="databaseType" value="h2" /> –>
      <property name="dataSource" ref="dContractDataSource" />
      <property name="transactionManager" ref="dContractTransactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="deploymentResources" value="classpath*:diagrams/TestProcess.bpmn" />
      <property name="jobExecutorActivate" value="true" />
      <property name="history" value="audit" />
      <!– ajout pour utiliser JPA / hibernate avec activiti –>
      <property name="jpaEntityManagerFactory" ref="dContractEntityManagerFactory" />
      <property name="jpaHandleTransaction" value="true" />
      <property name="jpaCloseEntityManager" value="true" />
   </bean>


   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />
   </bean>

   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="identityService" factory-bean="processEngine"
      factory-method="getIdentityService" />
   <bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" />

</beans>


and my properties file is :

#### H2 ######

dcontract.database.driverClass=org.h2.Driver
dcontract.database.url=jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000
dcontract.database.username=sa
dcontract.database.password=

# Depends on the underlying database system
jpa.dialect=org.hibernate.dialect.H2Dialect

# If true, create/update all relevant tables at startup.
# Only for local and dev environnements, do not activate in production.
jpa.generateDdl=true
jpa.addCustomFK=false
jpa.showSql=true


any help is welcome…

Outcomes