Announcement Announcement Module
Collapse
No announcement yet.
Problems with Spring Batch and JPA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with Spring Batch and JPA

    Hi,

    i have problems to use spring batch with my jpa configuration. My configuration looks like this:
    Code:
      
    <beans profile="production">
        <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/Ds" />
      </beans>
    
      <beans profile="development,mock">
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
          <property name="username" value="app" />
          <property name="password" value="app" />
          <property name="driverClassName" value="org.postgresql.Driver" />
          <property name="url" value="jdbc:postgresql://localhost:5432/db" />
        </bean>
      </beans>
    
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="my.package" />
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true" />
          </bean>
        </property>
        <property name="jpaProperties">
          <props>
            <prop key="hibernate.hbm2ddl.auto">validate</prop>
            <prop key="hibernate.show_sql">false</prop>
          </props>
        </property>
        <property name="jpaDialect">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
        </property>
      </bean>
    
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
      </bean>
    
      <bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
        <property name="dataSource" ref="dataSource" />
      </bean>
     
      <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
      </bean>
    
      <bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager"/>
        <property name="isolationLevelForCreate" value="ISOLATION_DEFAULT"/>
      </bean>
    If i run my job i will get an exception, that a connection has been closed. If i use the ResourcelessTransactionManager for all job beans, it will works, but i can only use the JpaPagingItemReader but not the jpaItemWriter. If i create a separted dataSource bean with the same configuration, it will works until i deploy it on my integration enviroment, where the data source will be created over jndi. I use following versions:
    Spring Verison: 3.2.2.RELEASE
    Spring Batch Version: 2.1.9.RELEASE
    hibernate-entitymanager: 4.2.1.Final

    Here the full stack strace:
    Code:
    20:42:37.680 | ERROR | o.s.t.i.TransactionInterceptor | Application exception overridden by rollback exception
    org.springframework.dao.DataAccessResourceFailureException: PreparedStatementCallback; SQL [SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION from BATCH_JOB_EXECUTION E where JOB_INSTANCE_ID = ? and JOB_EXECUTION_ID = (SELECT max(JOB_EXECUTION_ID) from BATCH_JOB_EXECUTION E2 where E.JOB_INSTANCE_ID = E2.JOB_INSTANCE_ID)]; This connection has been closed.; nested exception is org.postgresql.util.PSQLException: This connection has been closed.
    	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:639) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:668) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:676) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:202) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:209) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.getLastJobExecution(JdbcJobExecutionDao.java:223) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
    	at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution(SimpleJobRepository.java:257) ~[spring-batch-core-2.1.9.RELEASE.jar:na]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_11]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_11]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_11]
    	at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_11]
    	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) ~[spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) ~[spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at $Proxy34.getLastJobExecution(Unknown Source) [na:na]
    	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:94) [spring-batch-core-2.1.9.RELEASE.jar:na]
    	at my.package.batch.LettershopSpringBatchService.startJob(LettershopSpringBatchService.java:42) [LettershopSpringBatchService.class:na]
    	at my.package.controller.demo.LettershopDemoController.batch(LettershopDemoController.java:67) [LettershopDemoController.class:na]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_11]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_11]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_11]
    	at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_11]
    	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) [spring-web-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) [spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745) [spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686) [spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [spring-webmvc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    ....
    	at java.lang.Thread.run(Thread.java:722) [na:1.7.0_11]
    Caused by: org.postgresql.util.PSQLException: This connection has been closed.
    	at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714) ~[postgresql-9.1-901.jdbc4.jar:na]
    	at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareStatement(AbstractJdbc3Connection.java:274) ~[postgresql-9.1-901.jdbc4.jar:na]
    	at org.postgresql.jdbc2.AbstractJdbc2Connection.prepareStatement(AbstractJdbc2Connection.java:198) ~[postgresql-9.1-901.jdbc4.jar:na]
    	at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1444) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:583) ~[spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    	... 61 common frames omitted

  • #2
    The HibernateJpaDialect in Spring 3.2.2 is not compatible with Hibernate 4.2. The latest 3.2.3 contains a fix for this, try it out.

    Comment


    • #3
      Thx it works with Spring 3.2.3. This problem was very frustrating

      Comment

      Working...
      X