2 Replies Latest reply on Oct 31, 2008 3:13 AM by terryb

    EntityQuery Restrictions IndexOutOfBoundsException

    terryb

      I have a MyList bean extending EntityQuery. It uses restrictions and works fine if restrictions are all preset BUT throws following error if I conditionally add a new  restriction depending on user action on webpage. See getRestrictions() method below.


      I know the problem, but not sure how to workaround it. It is due to number of restrictionParameters and restrictions returned by getRestrictions() getting out of sink.


      In Seam's query.java class, method parseEjbql(), the 'restrictionParameters' is populated during first call to getRestrictions(), ie before my conditional restriciton gets added. During follow up calls my conditional restrictions is gets added by 'restrictionParameters' is not updated.


      Is this a bug and/or is there anywork around for it?


      Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
              at java.util.ArrayList.RangeCheck(ArrayList.java:547)
              at java.util.ArrayList.get(ArrayList.java:322)
              at org.jboss.seam.framework.Query.getRenderedEjbql(Query.java:232)
              at org.jboss.seam.framework.Query.getCountEjbql(Query.java:264)
              at org.jboss.seam.framework.EntityQuery.createCountQuery(EntityQuery.java:198)
              at org.jboss.seam.framework.EntityQuery.initResultCount(EntityQuery.java:128)
              at org.jboss.seam.framework.EntityQuery.getResultCount(EntityQuery.java:120)
             



      private static final String[] RESTRICTIONS = {
      lower(campus.id) = #{courseSysCourseList.selectedCampusId}",

      "lower(course.id) = #{courseSysCourseList.selectedCourseId}",
      };




          @Override
          public List<String> getRestrictions() {
             
              List<String> restrictrions = new ArrayList<String>();
             
              for (String restriction : RESTRICTIONS) {
                      restrictrions.add(restriction);
              }

      *** Exception occurs when following restriction is added
              if (isFullTime != null) {
                      restrictrions.add("course.fullTime=true");     
              }
              return restrictrions;
      }