Results 1 to 7 of 7

Thread: Late binding is not working with Spring 3.0.x

  1. #1
    Join Date
    Sep 2010
    Posts
    6

    Default Late binding is not working with Spring 3.0.x

    Hi,
    I'm using spring-batch 2.1.3. RELEASE and wanted to use it with spring 3.0.5.RELEASE. However, I found that late binding is not working (at least for stepExecutionContext) with this configuration. If I change the project to use spring 2.5.6 then it's working perfectly.
    I'm using stepExecutionContext late binding for the itemReader in partitioned configuration as below:
    Code:
    	<bean class="org.springframework.batch.core.scope.StepScope" />
    
    	<job id="partitionJdbcJob" xmlns="http://www.springframework.org/schema/batch">
    		<step id="step1">
    			<partition step="step" partitioner="partitioner">
    				<handler grid-size="2" task-executor="taskExecutor"/>
    			</partition>
    		</step>
    	</job>
    
    	<step id="step" xmlns="http://www.springframework.org/schema/batch">
    		<tasklet allow-start-if-complete="true">
    			<chunk writer="writer" reader="reader" commit-interval="5" />
    			<listeners>
    				<listener ref="fileNameListener" />
    			</listeners>
    		</tasklet>
    	</step>
    
    	
    	<!-- ##### INFRASTRUCTURE ######## -->
    	<bean id="partitioner" class="com.test.batch.example.DataPartitioner">
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />
    
    	<bean id="fileNameListener" class="com.test.batch.example.OutputFileListener" scope="step">
    		<property name="path" value="file:./target/output/jdbc/" />
    	</bean>
    
    	<bean id="reader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">
    		<property name="dataSource" ref="dataSource" />
    		<property name="rowMapper">
    			<bean class="com.test.batch.example.IncomingDataRowMapper" />
    		</property>	
    		<property name="sql">
    			<value>
                    <![CDATA[
                        select ID, STATUS from INCOMING_DATA where DATA_TYPE = ?
                    ]]>
    			</value>
    		</property>
    		<property name="preparedStatementSetter">
    			<bean class="org.springframework.batch.core.resource.ListPreparedStatementSetter" scope="step">
    				<property name="parameters">
    					<list>
    						<value>#{stepExecutionContext[type]}</value>
    					</list>
    				</property>
    			</bean>
    		</property>
    	</bean>
    
    	<bean id="writer" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
    		<property name="resource" value="#{stepExecutionContext[outputFile]}" />
    		<property name="lineAggregator">
    			<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
    				<property name="delimiter" value="," />
    				<property name="fieldExtractor">
    					<bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
    						<property name="names" value="id,status" />
    					</bean>
    				</property>
    			</bean>
    		</property>
    	</bean>
    During execution of itemReader I'm getting the error:
    Code:
    2010-10-26 12:54:10,244 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step>
    org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [select data_type from incoming_data group by data_type]; SQL state [null]; error code [17004]; Niepoprawny typ kolumny; nested exception is java.sql.SQLException: Niepoprawny typ kolumny
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    ....
    Instead of the value determined by partitioner a null value is passed.

    If I changed the project to use spring 2.5.6 then it's working without any problems. Is it a known issue, or new bug ? Or I'm missing something...

    I'd appreciate for any help.

    P.S. In attachement you can find zipped STS project with spring 3.0 configured.

    Regards,
    Marcin
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    You need to add '...' around the map keys.

    Please see section 5.4 in the reference manual...

    Note
    If you are using Spring 3.0 (or above) the expressions in step-scoped beans are in the
    Spring Expression Language, a powerful general purpose language with many interesting
    features. To provide backward compatibility, if Spring Batch detects the presence of older
    versions of Spring it uses a native expression language that is less powerful, and has
    slightly different parsing rules. The main difference is that the map keys in the example
    above do not need to be quoted with Spring 2.5, but the quotes are mandatory in Spring 3.0.
    Last edited by Gary Russell; Oct 26th, 2010 at 06:49 AM.

  3. #3
    Join Date
    Sep 2010
    Posts
    6

    Default

    Hi Gary,
    I checked that and it's working the same.
    I did like follows:
    Code:
    		<property name="preparedStatementSetter">
    			<bean class="org.springframework.batch.core.resource.ListPreparedStatementSetter" scope="step">
    				<property name="parameters">
    					<list>
    						<value>#{stepExecutionContext['type']}</value>
    					</list>
    				</property>
    			</bean>
    		</property>
    and same problem happens.

    Quote Originally Posted by Gary Russell View Post
    You need to add '' around the map keys.

    Please see section 5.4 in the reference manual...

    Note
    If you are using Spring 3.0 (or above) the expressions in step-scoped beans are in the
    Spring Expression Language, a powerful general purpose language with many interesting
    features. To provide backward compatibility, if Spring Batch detects the presence of older
    versions of Spring it uses a native expression language that is less powerful, and has
    slightly different parsing rules. The main difference is that the map keys in the example
    above do not need to be quoted with Spring 2.5, but the quotes are mandatory in Spring 3.0.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    Looks like this error is coming from a different query...

    The query in the config is..

    Code:
    select ID, STATUS from INCOMING_DATA where DATA_TYPE = ?
    The query in the error is

    Code:
    select data_type from incoming_data group by data_type
    Can you provide more of your config and the full stack trace?

  5. #5
    Join Date
    Apr 2008
    Location
    Philadelphia, US
    Posts
    198

    Arrow

    @czeczek,

    I have a partition job that uses late bound parameters through "#{stepExecutionContext[minValue]} / #{stepExecutionContext[maxValue]}".

    Saw your problem, wanted to see if it is caused by 3.0.5-RELEASE, but both "3.0.4" and "3.0.5" worked fine with and without single quotes around map keys.

    Just to narrow down the root cause.

    /Anatoly
    Humans are stateful and mutable beings that have no problems processing many things concurrently and share state with others + they are usually "coupled"

  6. #6
    Join Date
    Sep 2010
    Posts
    6

    Default

    My mistake. I didn't notice that the exception is about different query. Previously I was struggling with the itemReader config and when changed something I didn't check that spring is complaining about different query.
    Already fixed that and now it's working perfectly. The problem was that I was using obsolete jdbcTemplate.query() method that was working in spring 2.5.6 but in 3.0.5 is not working the same having problems mapping columns.
    I changed it to use generic RowMapper and now it's fine.

    I appreciate for the help and sorry for my mistake.

    Marcin

    Quote Originally Posted by Gary Russell View Post
    Looks like this error is coming from a different query...

    The query in the config is..

    Code:
    select ID, STATUS from INCOMING_DATA where DATA_TYPE = ?
    The query in the error is

    Code:
    select data_type from incoming_data group by data_type
    Can you provide more of your config and the full stack trace?

  7. #7
    Join Date
    Oct 2010
    Posts
    3

    Default

    Hi
    Great work Garry
    I know that forums are a good place to learn and interact with other people , so that People can share their experience with each other.
    my lead system pro
    Last edited by A.Aroan; Nov 2nd, 2010 at 03:51 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
  •