8 Replies Latest reply on Nov 7, 2008 5:47 PM by Ingo Jobling

    2.1.0 CR1 - Issue in getResultList

    kanwar sangha Newbie

      Hi,


      The getResultList() is throwing exceptions in the latest build of seam (2.1.0 CR1).



      [#|2008-10-02T09:23:26.013+0530|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=21;_ThreadName=httpSSLWorkerThread-8080-0;_RequestID=c0bc8b99-c91f-4770-9991-babdad503395;|
      
      java.lang.ClassCastException: java.lang.String
      
           at org.jboss.seam.framework.Query.parseEjbql(Query.java:220)
      
           at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:169)
      
           at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:73)
      
           at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:65)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
           at java.lang.reflect.Method.invoke(Method.java:585)
      
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)





      Another exception thrown if result set is empty. These conditions were working fine in the previous version -



      Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
      
           at java.util.ArrayList.RangeCheck(ArrayList.java:546)
      
           at java.util.ArrayList.get(ArrayList.java:321)
      
           at org.jboss.seam.framework.Query.getRenderedEjbql(Query.java:240)
      
           at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:175)
      
           at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:73)
      
           at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:65)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
           at java.lang.reflect.Method.invoke(Method.java:585)
      
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)









        • 1. Re: 2.1.0 CR1 - Issue in getResultList
          Nicklas Karlsson Master

          Details, details. Show code, tell versions (sun-appserver9.1?)

          • 2. Re: 2.1.0 CR1 - Issue in getResultList
            kanwar sangha Newbie

            we are extending EntityQuery and overriding



            @Override
                public List getResultList() {
                      edList = super.getResultList();
                      return edList;
                }




            Sun-appserver 9.1
            mysql version - 6.0
            Seam - 2.1.0.CR1



            exception


            Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
            
                 at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            
                 at java.util.ArrayList.get(ArrayList.java:321)
            
                 at org.jboss.seam.framework.Query.getRenderedEjbql(Query.java:240)
            
                 at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:175)
            
                 at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:73)
            
                 at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:65)
            
                 at com.prod.sps.session.EventdefinitionList.getResultList(EventdefinitionList.java:44)



            • 3. Re: 2.1.0 CR1 - Issue in getResultList
              Pete Muir Master

              Please file an issue in JIRA, with a simple example we can use to reproduce asap so we can get the fix in for the next release.

              • 4. Re: 2.1.0 CR1 - Issue in getResultList
                kanwar sangha Newbie

                earlier version had this in the generated entityList.java file which was causing the issue -



                @Override
                public List<String> getRestrictions() {
                return Arrays.asList(RESTRICTIONS);
                }
                




                New version generates the following-



                @Override
                public List getRestrictions() {
                // TODO Auto-generated method stub
                return super.getRestrictions();
                } 


                • 5. Re: 2.1.0 CR1 - Issue in getResultList
                  Julien Kronegg Novice

                  Hi kanwar,
                  I got the same issue using Seam 2.1.1-SNAPSHOT #340.


                  This is not a bug, but a Seam 2.0.x->2.1.x migration issue, as the seam21migration.txt file state the following:


                  Seam Application Framework Changes
                  ----------------------------------
                  
                  Seam now expects value expressions for a number of properties 
                  (entityHome.createdMessage, entityHome.updatedMessage, entityHome.deletedMessage
                  and entityQuery.restrictions); if you are using components.xml to configure your
                  objects, you don't need to make any changes. If you are extending the objects in
                  Java, you just need to create a value expression; for example:
                  
                  public ValueExpression getCreatedMessage() { return createValueExpression("New person #{person.firstName} #{person.lastName} created"); }
                  



                  As me, you probably had the following RESTRICTIONS in your subclass of EntityQuery:


                  public class MyobjectList extends EntityQuery {
                    private static final String[] RESTRICTIONS = {"lower(myobject.name) like concat(lower(#{myobjectList.myobject.name}),'%')",};
                    ...
                    public List<String> getRestrictions() { return Arrays.asList(RESTRICTIONS); }
                  }



                  You must convert the RESTRICTIONS String[] to a org.jboss.seam.core.Expressions.ValueExpression[] (and getRestrictions() must return a List<ValueExpression>). Even simpler, you can use the following convenience method:


                  import org.jboss.seam.core.Expressions.ValueExpression;
                  public class MyobjectList extends EntityQuery {
                    ...
                    public List<ValueExpression> getRestrictions() {
                      setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                      return super.getRestrictions();
                    }
                  }



                  I did it, it worked like a charm.


                  By the way, the IndexOutOfBoundException may be a different problem, as the org.jboss.seam.framework.Query.getRenderedEjbql() source code states at line 240:


                    for (int i=0; i<getRestrictions().size(); i++)
                    {
                      Object parameterValue = restrictionParameters.get(i).getValue();
                  



                  Notice the for's i<getRestrictions().size() boundary and the restrictionParameters.get(i) which may cause the problem.


                  Could you correct the restrictions migration problem and retry to see if the IndexOutOfBoundException can be reproduced?

                  • 6. Re: 2.1.0 CR1 - Issue in getResultList
                    Ingo Jobling Master

                    Hi Julien,


                    Thanks so much for posting this, I am converting my EntityQuery classes as you suggested:


                    @Override
                    public List<ValueExpression> getRestrictions()
                    {
                         setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
                         return super.getRestrictions();
                    }



                    The only thing is that I get a warning :


                    Expressions.ValueExpression is a raw type. References to generic type Expressions.ValueExpression<T> should be parameterized     


                    Oddly enough, this warning is not issued for the getRestrictions method in the base class, Query.

                    • 7. Re: 2.1.0 CR1 - Issue in getResultList
                      Ingo Jobling Master

                      Calling setRestrictionExpressionStrings) does not work for me, it causes parsedRestrictions to be set to null, resulting in a NullPointerException


                      Line 240 in Query class:


                      getRestrictions calls setRestrictionExpressionStrings, which calls setRestrictions, which sets parsedRestrictions to null;


                        for (int i=0; i<getRestrictions().size(); i++)
                      
                         (snip)
                                 builder.append( parsedRestrictions.get(i) );
                       
                      
                      




                      Here is what works for me:


                       
                      @Override
                      public List<ValueExpression> getRestrictions()
                      {
                           return toValueExpressionList(Arrays.asList(RESTRICTIONS));
                      }
                      
                      public List<ValueExpression> toValueExpressionList(List<String> expressionStrings)
                      {
                         List<ValueExpression> expressionList = new ArrayList<ValueExpression>(expressionStrings.size());
                         for (String expressionString : expressionStrings) {
                              expressionList.add(Expressions.instance().createValueExpression(expressionString));
                         }
                         return expressionList;
                      }



                      • 8. Re: 2.1.0 CR1 - Issue in getResultList
                        Ingo Jobling Master

                        Correct implementation is posted here (call setRestrictionExpressionStrings from constructor, not from getRestrictions)


                        GetRestrictionsInSeam21