Use jobParameters value in HibernateCursorItemReader HQL

October 8, 2010 at 5:03 pm | Posted in Uncategorized | 4 Comments
Tags: , ,

When ItemReader, ItemWriter, or ItemProcessor need to use JobParameters, you can set their bean scope to “step” and able to reference parameters.

  • doesn’t need to use spring3
  • bean needs to be a “step” scope.
  • expressions are  “#{}” or “%{}”.
    impl is : org.springframework.batch.core.scope.StepScope.ExpressionHider

Here, I pass “from_date” as jobParameter, and bind it to the item reader HQL of HibernateCursorItemReader.

  <bean id="hibernateReader"
         class="org.springframework.batch.item.database.HibernateCursorItemReader"
         scope="step">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="queryString">
       <value>
          <![CDATA[ from Something where start_date <= :reqFromDate ]]>
       </value>
    </property>
    <property name="parameterValues">
      <map>
        <entry key="reqFromDate" value="#{jobParameters['from_date']}"/>
      </map>
    </property>
  </bean>
Advertisements

Blog at WordPress.com.
Entries and comments feeds.