1 Reply Latest reply on Aug 25, 2005 11:47 AM by Emmanuel Bernard

    Query with parameter

    J-C jc Apprentice

      Hi,

      I wrote the following code

      Query query = em
       .createQuery("SELECT node FROM NodeBO node WHERE node.parent = :aParent");
       query.setParameter("aParent", parent);
       Collection col = query.getResultList();
       LOGGER.info("Number of children:" + col.size());


      It should return 1 object but it does not return it.

      If I write it another way, the query work fine:
      Query query = em
       .createQuery("SELECT node FROM NodeBO node WHERE node.parent.id = :aParent");
       query.setParameter("aParent", parent.getId());
       Collection col = query.getResultList();
       LOGGER.info("Number of children:" + col.size());


      Is it possible to give persitent object as parmater in a query ? What's wrong with the first way to writtte the query ?

      J-C