Announcement Announcement Module
Collapse
No announcement yet.
HibernateCursorItemReader(Cannot open an already opened ItemReader, call close first) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateCursorItemReader(Cannot open an already opened ItemReader, call close first)

    Hi all ,

    i got Cannot open an already opened ItemReader, call close first exception when using HibernateCursorItemReader class as itemreader.

    my config :

    <bean id="customerReader" parent="daoTemplate" scope="prototype" class="org.springframework.batch.item.database.Hib ernateCursorItemReader">
    <property name="queryString" value=" from Customer c " />
    </bean>

    <bean id="customerWriter" parent="writerTemplate" scope="step">
    <property name="lineAggregator"><ref local="customerLineAggregator" /> </property>
    <property name="resource" value="#{stepExecutionContext[outputFile]}" />
    </bean>

    and for the partitioning :

    <bean name="generatePartitionCustomer:master" class="org.springframework.batch.core.partition.su pport.PartitionStep">
    <property name="jobRepository" ref="jobRepository" />
    <property name="stepExecutionSplitter">
    <bean class="org.springframework.batch.core.partition.su pport.SimpleStepExecutionSplitter">
    <constructor-arg ref="jobRepository" />
    <constructor-arg ref="generatePartitionCustomerStep" />
    <constructor-arg ref="companyPartitioner" />
    </bean>
    </property>
    <property name="partitionHandler">
    <bean class="org.springframework.batch.core.partition.su pport.TaskExecutorPartitionHandler">
    <property name="taskExecutor">
    <ref local="threadPoolTaskExecutor"/>
    </property>
    <property name="step" ref="generatePartitionCustomerStep" />
    </bean>
    </property>
    </bean>

    <step id="generatePartitionCustomerStep" xmlns="http://www.springframework.org/schema/batch">
    <tasklet job-repository="jobRepository" transaction-manager="transactionManager">
    <chunk reader="customerReader" writer="customerWriter"
    commit-interval="${batch.commit.interval}" task-executor="threadPoolTaskExecutor" />
    <listeners>
    <listener ref="generateCustomerListener"/>
    </listeners>
    </tasklet>
    </step>

    my first analysis is itemreader's scope is still 'singleton' although i had declared it as 'prototype' .

    is my analysis is true or there are other thing's that throw this execption ?

    Please help ,Thanks .

    exception trace :

    ERROR [threadPoolTaskExecutor-4] (AbstractStep.java:execute:215) - Encountered an error executing the step
    org.springframework.batch.item.ItemStreamException : Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.open(AbstractItemCou ntingItemStreamItemReader.java:139)
    at org.springframework.batch.item.support.CompositeIt emStream.open(CompositeItemStream.java:98)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.open(TaskletStep.java:379)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:195)
    at org.springframework.batch.core.partition.support.T askExecutorPartitionHandler$1.call(TaskExecutorPar titionHandler.java:108)
    at org.springframework.batch.core.partition.support.T askExecutorPartitionHandler$1.call(TaskExecutorPar titionHandler.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.lang.IllegalStateException: Cannot open an already opened ItemReader, call close first
    at org.springframework.util.Assert.state(Assert.java: 384)
    at org.springframework.batch.item.database.HibernateC ursorItemReader.doOpen(HibernateCursorItemReader.j ava:199)
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.open(AbstractItemCou ntingItemStreamItemReader.java:137)
    ... 10 more

  • #2
    my first analysis is itemreader's scope is still 'singleton' although i had declared it as 'prototype' .
    You only inject it once, so you are only going to get one instance. Why don't you use scope="step"?

    Please use [code][/code] tags to post code and stacktraces.

    Comment


    • #3
      Originally posted by Dave Syer View Post
      You only inject it once, so you are only going to get one instance. Why don't you use scope="step"?

      Please use [code][/code] tags to post code and stacktraces.


      Dear Dave Syer,

      thanks for help

      Comment

      Working...
      X