0 Replies Latest reply on Dec 7, 2007 3:58 AM by Georges Berscheid

    Hibernate query parameter

    Georges Berscheid Newbie

      Hi,

      I am having problems with rather simple Hibernate queries not returning the results I would expect when using query parameters:

      Account account = (Account) entityManager
       .createQuery("SELECT c.account FROM Customer c WHERE c.salesperson.name = :salesname")
       .setParameter("salesname", salesGuyname).getSingleResult();
      

      -> 0 results (NoResultException)

      However, it works if I don't use query parameters and create the query string with concatenation:
      Account account = (Account) entityManager
       .createQuery("SELECT c.account FROM Customer c WHERE c.salesperson.name = '" + salesGuyname + "'")
       .getSingleResult();
      

      -> 1 result (the one I'm expecting)

      I'm using JBoss 4.2.2 with MySQL 4.1. Does anyone have an idea where this could come from?

      Thanks,
      Georges