Announcement Announcement Module
Collapse
No announcement yet.
getJpaTemplate().findQueryByName() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    You should use the findByNamedQueryAndNamedParams since you are using a named parameter "status".

    See: JpaTemplate.findByNamedQueryAndNamedParams(java.la ng.String, java.util.Map)

    Comment


    • #3
      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.

      Comment


      • #4
        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

        Comment

        Working...
        X