1 Reply Latest reply on May 25, 2009 6:51 PM by jamesjmp

    Problem with a query

      Hello,


      I'm trying to do a query in seam but I don't have good results. I have the class:


      @Name("Actividad")
      public class Actividad extends EntityQuery {
      
       @In EntityManager entityManager;
              
       public List camposActividad(String aid){
                              
              List result = entityManager.createQuery("select u.user, r.rol from Nmusuario u, Nmrol r" +
                                              "where u.id:=idusuario").setParameter("idusuario", aid).getResultList();
                              
                      return result;
                      }       
      }




      Then when I call the method Actividad.camposActividad('usuario1') return ejbql is null.


      Can anybody tell me why it happends?


      Thanks.

        • 1. Re: Problem with a query

          If you use an EntityQuery subclass, you must assign the string with the query to ejbql member, and if you have parameters define them in restrictions member.
          When you invoke your EntityQuery subclass component's getResultList two things happens:
          1.- the query to be executed is the one that Ejbql provides
          2.- restrictions are taken into account
          3.- query is executed and its result returned


          For example (Seam 2.1.1):


          
              private static final String EJBQL = "select settlementInstruction from SettlementInstruction settlementInstruction";
          
              private static final String[] RESTRICTIONS = {
                      "lower(settlementInstruction.orderType) like concat(lower(#{settlementInstructionList.settlementInstruction.orderType}),'%')", };
          
              private SettlementInstruction settlementInstruction = new SettlementInstruction();
          
              public SettlementInstructionList() {
                  setEjbql(EJBQL);
               setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                  setMaxResults(25);
              }
          
              public SettlementInstruction getSettlementInstruction() {
                  return settlementInstruction;
              }