Results 1 to 2 of 2

Thread: Job Repository - CannotCreateTransactionException

  1. #1
    Join Date
    Jul 2010
    Posts
    13

    Default Job Repository - CannotCreateTransactionException

    Hello,
    I am trying to use Spring Batch with an HSQLDB repository. I am getting the following error when starting up my job:
    org.springframework.transaction.CannotCreateTransa ctionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: invalid transaction state: active SQL-transaction

    The context configuration is as follows:


    Code:
    	<bean id="transactionManager"
    	    class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
    	  	<property name="dataSource" ref="dataSource"/>
    		<property name="nestedTransactionAllowed" value="true" />
    		<property name="defaultTimeout" value="30" />	  
    	</bean>	
    
    
    	<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"> 
    		<property name="dataSource" ref="dataSource" />
     		<property name="tablePrefix" value="batch_"/>			
    	</bean>
    
    	<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher" autowire-candidate="true">
    		<property name="jobRepository" ref="ajobRepository"/>
    		<property name="taskExecutor">
    			<bean class="org.springframework.core.task.SyncTaskExecutor" />
     		</property>
    	</bean>
     
    	<bean id ="dq-etl-jobRepository"
    		class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="transactionManager" ref="transactionManager"/>
     		<property name="databaseType" value="hsql" />
      		<property name="tablePrefix" value="batch_"/>	
      	</bean>
    	
    	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">                  
    		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />                
    		<property name="url" value="jdbc:hsqldb:hsql://localhost:9000/jobsdb" />                
    	   	<property name="maxIdle" value="10"/>    
    		<property name="maxActive" value="100"/>    
    		<property name="maxWait" value="10000"/> 
    		<property name="testOnBorrow" value="false"/>    
    		<property name="testWhileIdle" value="true"/>      
    		<property name="defaultAutoCommit" value="false"/>  
    	</bean>
    The job context:
    Code:
    <batch:step id="loadjob">	
    		 	<batch:tasklet transaction-manager="transactionManager" >  
    				<batch:chunk reader="importReader" processor="importProcessor" writer="compositeWriter" commit-interval="200"/>
    		 		  <batch:transaction-attributes isolation="READ_COMMITTED" 
                                    propagation="REQUIRES_NEW" />
    				<batch:listeners>
    					<batch:listener ref="aCacheJdbcWriter"/>
    					<batch:listener ref="aDwJdbcWriter"/>
    				</batch:listeners>
    			</batch:tasklet>
    		</batch:step>
    The error trace is:

    Code:
    1109 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTransactionManager  - Creating new transaction with name [org.springframework.batch.core.repository.JobRepository.getLastJobExecution]: PROPAGATION_REQUIRES_NEW,ISOLATION_SERIALIZABLE
    1437 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTransactionManager  - Acquired Connection [jdbc:hsqldb:hsql://localhost:9000/jobsdb, UserName=job_user HSQL Database Engine Driver] for JDBC transaction
    1437 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Changing isolation level of JDBC Connection [jdbc:hsqldb:hsql://localhost:9000/jobsdb, UserName=job_user, HSQL Database Engine Driver] to 8
    1453 [main] DEBUG org.springframework.jdbc.datasource.DataSourceUtils  - Returning JDBC Connection to DataSource
    When looking at this listing the "returning Datasource" .I do not see where it actually obtained the DataSource in the debug output. I have created a new repository just for testing and the error continues. I have removed all attribute specifications and relied on defaults, and the error continues.

    Using the in-memory repository results in everything working normal.
    I assume something minor/silly, but its identification escapes me.

    Thanks for you help

  2. #2
    Join Date
    Jul 2010
    Posts
    13

    Default

    It appears that this exception is thrown from HSQLDB only when we set the auto-commit mode to false. If true then everything appears to work fine, but I would be concerned about repository rollbacks and how they would be handled in such a scenario.

    Any comments?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •