2 Replies Latest reply on May 14, 2009 8:44 PM by israel.bgf

    JPQL - Query Parameter

    israel.bgf
      I know that this question doesnt is a Seam one, but i still need help. :)

      Supose the following situation:

      class ObjectA

      Integer id;
      List<ObjectB> list;

      How can i make a JPQL that retrives a list of ObjectA that have at least N ObjectB. N is variable number. Example:

      table ObjectA
      [id]
      1
      2
      ------------------
      table ObjectB
      [id] [fk_objectA]
      1 1
      2 1
      3 2

      My search method would be...

      List<ObjectA> search(List<ObjectB> param){
      return em.createQuery("from ObjectA o where o have at least these :param").setParameter("param",param).getResultlist()
      }

      If param is a list with ObjectB(id=1) it would retrieve: ObjectA(id=1), the same would be true if param was a list with [ObjectB(id=1),ObjectB(id=2)]

      Off course that this query don't work, but i want to do something like that. Is it possible? Or do i have to make a lot of string concatenation?

      Thanks!

      Israel
        • 1. Re: JPQL - Query Parameter
          sherkan777

          First, try to do it in pure SQL.
          Second, If u want to return ObjectB List U can map rout SQL query to Object


          .createNativeQuery(your query, Object.class);


          after that u can try to change it to H/EJB/JPQL query.

          • 2. Re: JPQL - Query Parameter
            israel.bgf

            The problem is that i'm still in the first step: try to do it in pure SQL. :)


            I can concat a lot of ands and ors but i dont think that it's a good practice. So that's why im asking.


            Thks in advance.