Results 1 to 9 of 9

Thread: HibernateCursorItemReader queryName parameters

  1. #1
    Join Date
    Jan 2010
    Location
    Nantes - France
    Posts
    5

    Default HibernateCursorItemReader queryName parameters

    Hi,

    I'm experiencing problems using HibernateCursorItemReader and trying to add parameters to my queryName.

    I thought I found a solution on the following thread : http://forum.springsource.org/showthread.php?t=73562

    I tried the last solution but I got the following error :
    Code:
    org.hibernate.QueryException: unexpected char: '#' [
    My query :
    Code:
    <query name="B_Auto">			
    <![CDATA[
    	From AutomateED a
    	where a.dat < trunc(sysdate - 15/1440)
    	and not exists (select 1 from EtatED e
    	where e.autoED.idauto = a.idauto
    	and e.compED.idcomp = #{jobParameters[idcomp]}
    	and e.gravED.idgrav = #{jobParameters[idgrav]})
    ]]></query>
    I add the parameters like that :
    Code:
    JobParameters params = new JobParametersBuilder().
    addLong("idcompagt", new Long(42)).
    addLong("idgraval", new Long(2)).
    toJobParameters();
    setJobParameters(params);
    I'm using Spring Batch 2.0.4.

    Thanks in advance for your help.

    Yann

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    It is not a valid HQL or JQL for that matter. The placeholders ONLY work if they are specified in the applicationContext NOT if they are part of the hbm file.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jan 2010
    Location
    Nantes - France
    Posts
    5

    Default

    Thanks Marten. In fact, I already tried to put my HQL in the application context and I got the same error.

    Doing that for example :
    Code:
    <bean id="hibernateAutoReader" class="org.springframework.batch.item.database.HibernateCursorItemReader">
    <property name="queryString">
    	<value>
            <![CDATA[
            From AutomateED a
    	where a.dat < trunc(sysdate - 15/1440)
    	and not exists (select 1 from EtatED e
    	where e.autoED.idauto = a.idauto
    	and e.compED.idcomp = #{jobParameters[idcomp]}
    	and e.gravED.idgrav = #{jobParameters[idgrav]})
            ]]>
    	</value>
    </property>
    <property name="sessionFactory" ref="sessionFactory" />
    </bean>

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    For that I suggest you read the full thread you initially pointed to... The answer is here.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jan 2010
    Location
    Nantes - France
    Posts
    5

    Default

    Thank you but the example on FlatFileItemReader doesn't really help me.

    Could it be an incompatibility between Spring and Spring Batch ? I'm using spring 2.5.6 and spring batch 2.0.4.

    My application context header might be wrong ?

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p"
    	xsi:schemaLocation="
    			http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
    			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    Maybe the only solution is to use a property file instead of parameters ?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    Sigh... I gave you the post with the answer as I suggest read that thread, which you used yourself also.

    Quote Originally Posted by Dave Syer
    Your reader needs to be in step scope.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Jan 2010
    Location
    Nantes - France
    Posts
    5

    Default

    Thanks ... I put this scope in another configuration (adding quote etc...) and it didn't work. See you next time

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I really suggest you read the reference guide on using step scope and how to configure it, also make sure that the step scope is available and that you use a scoped-proxy (only specifing scope="step" isn't enough!).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    Jan 2010
    Location
    Nantes - France
    Posts
    5

    Default

    In fact, you were right yesterday. This problem is solved thanks to you.

Tags for this Thread

Posting Permissions

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