2 Replies Latest reply on Nov 17, 2010 5:43 PM by waltc

    EntityQuery RESTRICTIONS

    waltc

      Yes I really did check google and forum first. From what I can tell this should work.


      I have a single Seam application that, depending on which tab is selected a different subset of the table corpus should be displayed. Everything else is identical.


      The ejbql is a simple select compositeActivity from CompositeActivity compositeActivity


      An earlier version had the where clause embedded but now I must expand.


      In the action bean I added the following methods:




             public void setCondition1() {
                      String restrict[] = {
                                      "compositeActivity.docType = 1",
                                      " compositeActivity.engineType = 0"
                      };
                      compositeActivityList.setRestrictionExpressionStrings(Arrays.asList(restrict));
              }
              public void setPCOndition2() {
                      String restrict[] = {
                                      "compositeActivity.docType = 0", 
                                      " compositeActivity.engineType = 0"
                      };
                      compositeActivityList.setRestrictionExpressionStrings(Arrays.asList(restrict));
              }
              public void setCondition3() {
                      String restrict[] = {
                                      "compositeActivity.docType = 0",
                                      " compositeActivity.engineType = 1"
                      };
                      compositeActivityList.setRestrictionExpressionStrings(Arrays.asList(restrict));
              }
              public void setCondition4() {
                      String restrict[] = {
                                      "compositeActivity.docType = 1",
                                      " compositeActivity.engineType = 1"
                      };
                      compositeActivityList.setRestrictionExpressionStrings(Arrays.asList(restrict));
              }
      


      I invoke these methods selectively in the facet definition as the tab is selected


      This fails with:


      Caused by: java.lang.IllegalArgumentException: there should be exactly one value binding in a restriction: org.jboss.seam.core.Expressions$1@72330de8


      I guess the good news is, by virtue of the exception, my

      #{DailyActivity.setCondition1()}

      worked.
      I do not understand what it doesn't like in the restrictions itself.


      Thanks,
      Walt

        • 1. Re: EntityQuery RESTRICTIONS
          gonzalad

          You should check that each one of your restrictionExpression contains one EL (and only one).


          So, for instance this doesn't work :


          "compositeActivity.docType = 1"
          



          But this should work :


          "compositeActivity.docType = #{1}"
          



          Another way I think (not sure) is to create your add your static restrictions in your ejbql.


          "select compositeActivity from CompositeActivity compositeActivity where compositeActivity.docType = 1"
          


          • 2. Re: EntityQuery RESTRICTIONS
            waltc

            Thanks! I will try that tomorrow. What I did was effectively what you suggested and I call public method to set a new ejbqa string.


            You'll note the name of that entity is CompositeActivity. I did that to combine multiple takes. I think, for the most part, Seam...or maybe it is just Container Managed Persistence in general, doesn't do a good job of allowing programmatically pointing a single Entity to a different data source. From what I can gather if I want to change from a Container Managed to an Application Managed Persistence I could do that but then I'd own the whole lifecycle.


            Anyway I wanted to get restrictions working that were not via a seam-gen subpanel search window.