Results 1 to 4 of 4

Thread: getJpaTemplate().findQueryByName()

  1. #1
    Join Date
    Aug 2007
    Posts
    5

    Default getJpaTemplate().findQueryByName()

    Hi all,
    Im using the above method to get a named query.

    Named query.......

    @NamedQuery(name = "Task.findByStatus", query = "SELECT t FROM Task t WHERE t.status = :status")


    Function call.........

    return (Task) getJpaTemplate().findByNamedQuery("Task.findByStat us","NEW");


    Error...........

    Caused an ERROR
    You have attempted to set a parameter at position 1 which does not exist in this query string SELECT t FROM Task t WHERE t.status = :status.; nested exception is java.lang.IllegalArgumentException: You have attempted to set a parameter at position 1 which does not exist in this query string SELECT t FROM Task t WHERE t.status = :status.
    org.springframework.dao.InvalidDataAccessApiUsageE xception: You have attempted to set a parameter at position 1 which does not exist in this query string SELECT t FROM Task t WHERE t.status = :status.; nested exception is java.lang.IllegalArgumentException: You have attempted to set a parameter at position 1 which does not exist in this query string SELECT t FROM Task t WHERE t.status = :status.
    Caused by: java.lang.IllegalArgumentException: You have attempted to set a parameter at position 1 which does not exist in this query string SELECT t FROM Task t WHERE t.status = :status.
    at oracle.toplink.essentials.internal.ejb.cmp3.base.E JBQueryImpl.setParameterInternal(EJBQueryImpl.java :633)
    at oracle.toplink.essentials.internal.ejb.cmp3.EJBQue ryImpl.setParameter(EJBQueryImpl.java:194)
    at org.springframework.orm.jpa.JpaTemplate$11.doInJpa (JpaTemplate.java:343)
    at org.springframework.orm.jpa.JpaTemplate.execute(Jp aTemplate.java:191)
    at org.springframework.orm.jpa.JpaTemplate.executeFin d(JpaTemplate.java:158)
    at org.springframework.orm.jpa.JpaTemplate.findByName dQuery(JpaTemplate.java:338)


    ......................


    I also tried with hibernate but no luck same error.

    org.hibernate.HibernateException: could not parameter[1].......something similar to this

    I would really appreciate if anyone has seen this kind of error and could help me out.

    Thanks
    Sri

  2. #2
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    You should use the findByNamedQueryAndNamedParams since you are using a named parameter "status".

    See: JpaTemplate.findByNamedQueryAndNamedParams(java.la ng.String, java.util.Map)
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  3. #3
    Join Date
    Aug 2007
    Posts
    5

    Default

    Quote Originally Posted by trisberg View Post
    You should use the findByNamedQueryAndNamedParams since you are using a named parameter "status".

    See: JpaTemplate.findByNamedQueryAndNamedParams(java.la ng.String, java.util.Map)
    It worked. Thanks so much.

  4. #4
    Join Date
    Aug 2008
    Posts
    1

    Smile

    Map<String,String> paramMap=new HashMap<String, String>();

    paramMap.put("xxx", "ikram");

    List list = getJpaTemplate().findByNamedQueryAndNamedParams("g etxxxquery", paramMap);

    IN ENTITY

    @NamedQuery(name = "getxxxquery", query = "SELECT x FROM ENTITY x WHERE x.name= :xxx")

    Hope this helps

Posting Permissions

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