4 Replies Latest reply on Sep 10, 2009 10:51 PM by davestar

    problem with EL restrictions for simple query

    davestar

      can someone please tell me how I can get the restrictions to work for this simple query?
      The below code does not work.  It ignores the restriction.
      I also tried the EL with the oracleUserName within quotes that treats the parameter as a literal.



              private static final String EJBQL = "select employee from Employee employee";
      
           public Employee getEmployee(String oracleUserName){
                employee = new Employee();
                employee.setId(new EmployeeId());
                setEjbql(EJBQL);
                String[] EMPBYUSERNAME_RESTRICTIONS = {
                          "lower(employee.oracleUsername) = #{oracleUserName}",};
                setRestrictionExpressionStrings(Arrays.asList(EMPBYUSERNAME_RESTRICTIONS));
                employee = getSingleResult();
                return employee;
           }
      




        • 1. Re: problem with EL restrictions for simple query
          pdhaigh

          Where do you set oracleUserName to an EL-accessible component?


          I think you might find that it ignores the restriction because


          #{oracleUserName}



          is resolving to null?

          • 2. Re: problem with EL restrictions for simple query
            davestar

            The oracleUserName is not null.  It is set by the code that calls the method getEmployee.



                     EmployeeRoleList empList = (EmployeeRoleList)Component.getInstance("employeeRoleList");
                    Employee employee = empList.getEmployee("sdwarf");



            • 3. Re: problem with EL restrictions for simple query
              psteininger

              David,


              If you make a reference to #{oracleUsername} Seam will try to locate a component called oracleUsername.
              What will likely work in your case is something like:



              String[] EMPBYUSERNAME_RESTRICTIONS = {"lower(employee.oracleUsername) = " + oracleUserName};



              you may need yo add single quotes around the value.


              • 4. Re: problem with EL restrictions for simple query
                davestar

                When I tried


                String[] EMPBYUSERNAME_RESTRICTIONS = {"lower(employee.oracleUsername) = " + oracleUserName};



                I get a



                javax.el.ELException: java.lang.IllegalArgumentException: there should be exactly one value binding in a restriction: org.jboss.seam.core.Expressions$1@16ec82

                When I add single quotes around the value, the restriction is ignored.


                Being able to add string variables to an expression would be really helpful, not sure if it's a seam limitation for now??