Results 1 to 9 of 9

Thread: Spring batch commit rollback problem

  1. #1

    Default Spring batch commit rollback problem

    Hi all,

    I am using spring batch 2.0 with hibernate 3.2.
    My requirement is if there are 100 records to process and exception occurs at 23rd, 50th and 88th record then only those 3 records will be rollbacked but rest will be processed.
    How do I achieve that.
    Please provide some code.

    Thanks in advance,
    Kousik

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

  3. #3

    Default

    No. Though I have the same configuration as your example but I am getting the typical exception given below.
    The SimpleRetryPolicy class is in my jar(spring-batch-infrastructure-2.0.4.RELEASE.jar).
    I am really surprised what is happening. I have no idea how this method is called fin batch flow.
    Please help.

    Note:- This error only occurs when I put the below lines in config file. Otherwise it runs but rollback do not happen.
    Code:
     skip-limit="10" and <skippable-exception-classes> java.lang.Exception
    					</skippable-exception-classes>
    Error stacktrace:-

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'upgradeJob': Cannot create in
    ner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.SimpleFlow] while setting bean prope
    rty 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with nam
    e '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.St
    ateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.b
    eans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner be
    an)' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; ne
    sted exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean
    )': Cannot resolve reference to bean 'runUpgradeBatch' while setting constructor argument; nested exception is org.sp
    ringframework.beans.factory.BeanCreationException: Error creating bean with name 'runUpgradeBatch': FactoryBean threw
     exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.batch.retry.polic
    y.SimpleRetryPolicy.<init>(I)V
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValue
    Resolver.java:230)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefiniti
    onValueResolver.java:122)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractA
    utowireCapableBeanFactory.java:1245)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowire
    CapableBeanFactory.java:1010)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowire
    CapableBeanFactory.java:472)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapable
    BeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCa
    pableBeanFactory.java:380)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRe
    gistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultLista
    bleBeanFactory.java:429)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApp
    licationContext.java:728)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380
    )
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.j
    ava:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.j
    ava:83)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:190)
            at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:254)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:585)
            at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:271)
            at java.lang.Thread.run(Thread.java:595)
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Can
    not create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.StateTransition] while
    setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCrea
    tionException: Error creating bean with name '(inner bean)': Cannot create inner bean '(inner bean)' of type [org.spr
    ingframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org
    .springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Cannot resolve re
    ference to bean 'runUpgradeBatch' while setting constructor argument; nested exception is org.springframework.beans.f
    actory.BeanCreationException: Error creating bean with name 'runUpgradeBatch': FactoryBean threw exception on object
    creation; nested exception is java.lang.NoSuchMethodError: org.springframework.batch.retry.policy.SimpleRetryPolicy.<
    init>(I)V
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValue
    Resolver.java:230)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefiniti
    onValueResolver.java:122)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionVal
    ueResolver.java:287)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefiniti
    onValueResolver.java:126)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractA
    utowireCapableBeanFactory.java:1245)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowire
    CapableBeanFactory.java:1010)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowire
    CapableBeanFactory.java:472)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapable
    BeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCa
    pableBeanFactory.java:380)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValue
    Resolver.java:219)
            ... 25 more
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Can
    not create inner bean '(inner bean)' of type [org.springframework.batch.core.job.flow.support.state.StepState] while
    setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error crea
    ting bean with name '(inner bean)': Cannot resolve reference to bean 'runUpgradeBatch' while setting constructor argu
    ment; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'run
    UpgradeBatch': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.s
    pringframework.batch.retry.policy.SimpleRetryPolicy.<init>(I)V
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValue
    Resolver.java:230)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefiniti
    onValueResolver.java:122)
            at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResol
    ver.java:479)
            at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorRes
    olver.java:353)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod
    (AbstractAutowireCapableBeanFactory.java:903)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAu
    towireCapableBeanFactory.java:817)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowire
    CapableBeanFactory.java:440)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapable
    BeanFactory.java:409)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCa
    pableBeanFactory.java:380)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValue
    Resolver.java:219)
            ... 35 more
    Last edited by kousik.majumder; Nov 23rd, 2010 at 02:38 AM.

  4. #4
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    Code:
    java.lang.NoSuchMethodError: org.springframework.batch.retry.polic
    y.SimpleRetryPolicy.<init>(I)V
    you should check your classpath and see if you don't have multiple versions of Spring Batch on it.

  5. #5

    Default

    As because I am using Maven so I have only one entry for this.
    Does this class reside in any other jar other than spring-batch-infrastructure?

    Code:
    <dependency>
    		<groupId>org.springframework.batch</groupId>
    		<artifactId>spring-batch-infrastructure</artifactId>
    		<version>2.0.4.RELEASE</version>
    	</dependency>

  6. #6
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    in Spring Batch 2.1.x, the SimpleRetryPolicy class is indeed in Spring Batch Infrastructure. I don't know about Spring Batch 2.0.x.
    Nevertheless, you should perhaps import Spring Batch Core instead (which depends on Spring Batch Infrastructure):

    Code:
    <dependency>
        <groupId>org.springframework.batch</groupId>
        <artifactId>spring-batch-core</artifactId>
        <version>2.0.4.RELEASE</version>
    </dependency>
    Be careful also about the version of the namespace you're using in your configuration file (2.0 and not 2.1)

  7. #7

    Default

    Yes. spring-batch-core is also there. Otherwise how the batch could have been run.
    And namespace version is also is 2.0. Then what else to do?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns="http://www.springframework.org/schema/batch"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    		http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
    		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    
    
    <job id="upgradeJob">
    		<step id="runUpgradeBatch">
    			<tasklet>
    				<chunk reader="readDb" processor="process" writer="opWriter"
    					 commit-interval="1"
    					 retry-limit="10">
    					 <retryable-exception-classes> 
    						java.lang.Exception
    					</retryable-exception-classes>
    				</chunk>				
    			</tasklet>
    		</step>
    	</job>
    .......

  8. #8
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

    The configuration looks good. Are you sure that you don't have any other Spring Batch JAR file on the classpath, because you're using Spring Batch Admin for example?

  9. #9

    Default

    My problem is solved.
    Actually the jar installed was of version 2.1 but was in version 2.0 in maven repo.
    Last edited by kousik.majumder; Nov 25th, 2010 at 08:15 AM.

Posting Permissions

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