Announcement Announcement Module
Collapse
No announcement yet.
Transactions and job execution Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transactions and job execution

    I have a chunk of code to start a job as well as record some external information on who started the job like so:
    Code:
    	@Transactional(propagation=Propagation.REQUIRED)
    	public JobBean startJob(String username, String jobName, String parameters) {
    		try {
    			long jobExecutionId = jobOperator.start(jobName, parameters);
    			this.recordJobExecutionInfo(jobExecutionId, username, null);
    			return new JobBean(jobExplorer.getJobExecution(jobExecutionId));
    		} catch (Exception e) {
    			throw new JobServiceException(e);
    		}
    	}
    and beans defined as:
    Code:
        <bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
            <property name="jobExplorer" ref="jobExplorer"/>
            <property name="jobLauncher" ref="jobLauncher"/>
            <property name="jobRegistry" ref="jobRegistry"/>
            <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="lobHandler" ref="lobHandler"/>
            <property name="isolationLevelForCreate" value="ISOLATION_DEFAULT"/>
    <!-- 		<property name="validateTransactionState" value="false"/> -->
        </bean>
    With the Transaction defined as REQUIRED, the job hangs. This looks to be something along the lines of what
    was reported in https://jira.springsource.org/browse/BATCH-1668

    If I remove the Transactional definition the job runs fine.

    Is there any way to get the job to run and still have this Transaction?
Working...
X