6 Replies Latest reply on Mar 28, 2008 9:22 AM by Feivel Frey

    Problem using EntityQuery

    Feivel Frey Newbie

      Hi,


      when I try to use a selection from selectOneMenu I receive always an exception like the following or a argument type mismatch


      Exception


      14:21:01,351 ERROR [SeamPhaseListener] uncaught exception
      javax.el.ELException: java.lang.IllegalArgumentException: java.lang.ClassCastException@5309d8
           at javax.el.BeanELResolver.setValue(BeanELResolver.java:116)
           at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:68)
           at com.sun.faces.el.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:93)
           at org.jboss.el.parser.AstPropertySuffix.setValue(AstPropertySuffix.java:73)
           at org.jboss.el.parser.AstValue.setValue(AstValue.java:84)
           at org.jboss.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:249)
           at org.jboss.seam.core.Expressions$1.setValue(Expressions.java:116)
           at org.jboss.seam.navigation.Pages.applyConvertedValidatedValuesToModel(Pages.java:781)
           at org.jboss.seam.navigation.Pages.postRestore(Pages.java:402)
           at org.jboss.seam.jsf.SeamPhaseListener.postRestorePage(SeamPhaseListener.java:533)
           at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:379)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:216)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:182)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Thread.java:595)
      Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@5309d8
           at sun.reflect.GeneratedMethodAccessor220.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at javax.el.BeanELResolver.setValue(BeanELResolver.java:108)
           ... 55 more
      14:21:01,511 ERROR [CachedConnectionValve] Application error: Faces Servlet did not complete its transaction
      



      Here my classes and page fragment


      @Entity
      @Name("logBook")
      public class LogBook extends StandardEntity implements Serializable{
           
           
           private Long id;
           
           private User user;
                
           private LogType action;
      
           public enum LogType{
                CREATE("CREATE"),
                UPDATE("UPDATE"),
                DELETE("DELETE"),
                LOGIN("LOGIN"),
                LOGINERROR("LOGINERROR"),
                QUERYERROR("QUERYERROR"),
                QUERY("QUERY");
                
                private String label;
                 
                LogType(String label){
                     this.label = label;
                }
        
                public String getLabel(){
                     return label;
                }
                
           }
           
           @Id @GeneratedValue
           public Long getId() {
                return id;
           }
           
           public void setId(Long id) {
                this.id = id;
           }
      
           public LogBook.LogType getAction() {
                return action;
           }
      
           public void setAction(LogBook.LogType aktion) {
                this.action = aktion;
           }
      
           @OneToOne(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
           public User getUser() {
                return user;
           }
      
           public void setUser(User benutzer) {
                this.user = benutzer;
           }
      
           
      }
      




      @Entity
      @Name("user")
      public class User extends StandardEntity implements java.io.Serializable {
      
           
           private Long id;
           
           private LogBook logBook;
      
      
           @Id
           @GeneratedValue
           @Column(name = "id", unique = true, nullable = false)
           public Long getId() {return this.id;}
           public void setId(Long id) {this.id = id;}
      
           
           @OneToOne(mappedBy="user", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
           public LogBook getLogBook() {
                return logBook;
           }
      
           public void setLogBook(LogBook logBook) {
                this.logBook = logBook;
           }
      }




      @Name("logBookList")
      public class LogBookList extends EntityQuery<LogBook>{
           
      
           @In
           private EntityManager entityManager;
           
           private static final String[] RESTRICTIONS = {
                "logBook.action = #{logBookList.logBook.action}",
                "logBook.user = #{logBookList.logBook.user}",};
           
           private LogBook logBook = new LogBook();
           
          @Override
          public String getEjbql() 
          { 
              return "select logBook from LogBook logBook";
          }
          
          @Override
           public Integer getMaxResults() {
                return 50;
           }
      
           public LogBook getLogBook() {
                return logBook;
           }
      
           @Override
           public List<String> getRestrictions() {
                return Arrays.asList(RESTRICTIONS);
           }
           
           @SuppressWarnings("unchecked")
           public List<User> getUserList(){
                return entityManager.createQuery("select distinct(lb.user) from LogBook lb").getResultList();
           }
      
           public User getUser() {
                return logBook.getUser();
           }
      }



      page statistikList.xhtml


      <rich:panel id="searchtogpanel" style="height:55px; background-color:#EEEEEE;">
                   <h:panelGrid columns="2">
                        <h:panelGroup>
                       <s:decorate template="../layout/display.xhtml">
                           <ui:define name="label">Aktion:</ui:define>
                               <h:selectOneMenu value="#{logBookList.logBook.user}">
                                    <s:selectItems value="#{logBookList.userList}" var="user" label="#{user.y20gpnum}" noSelectionLabel="Alle Benutzer"/>
                                    <s:convertEntity />
                               </h:selectOneMenu>
                                            </s:decorate>
                       </h:panelGroup>
                       <h:panelGroup>
                       <div class="actionButtons">
                            <h:commandButton id="suchen" action="/admin/statistikListe.xhtml" value="Suchen"/>
                        </div>
                        </h:panelGroup>
                   </h:panelGrid>
                </rich:panel>



      and corresponding statistikList.page.xml



      <?xml version="1.0" encoding="UTF-8"?>
      <page xmlns="http://jboss.com/products/seam/pages"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd">
            
         <param name="action" value="#{logBookList.logBook.action}"/>
         <param name="user" value="#{logBookList.logBook.user}"/>
      
      </page>
      



      Is this a bug or what I do wrong?


      Thanks

        • 1. Re: Problem using EntityQuery
          Pete Muir Master

          I don't see why you have page parameters in this.

          • 2. Re: Problem using EntityQuery
            Feivel Frey Newbie

            Pete Muir wrote on Mar 26, 2008 07:20 PM:


            I don't see why you have page parameters in this.


            Hi Pete,


            I have orientated me to Seam generated entity lists and there all search fields are also used as page parameters.


            And without these parameters the action search(see below) don't work as well.


            It's confusing that when I use the following no problem occur


            <h:selectOneMenu value="#{logBookList.logBook.action}">
                 <s:selectItems value="#{logTypes}" var="logType" label="#{logType.label}" noSelectionLabel="Alle Aktionen" />
                 <s:convertEnum />
            </h:selectOneMenu>




            but when I use


            <h:selectOneMenu value="#{logBookList.logBook.user}">
                 <s:selectItems value="#{distinctUsers}" var="distinctUser" label="#{distinctUser.y20gpnum}" noSelectionLabel="Alle Benutzer"/>
                 <s:convertEntity />
            </h:selectOneMenu>          
            


            the error above is thrown.

            • 3. Re: Problem using EntityQuery
              Feivel Frey Newbie

              Ok,


              I have found a solution get LogBookList working.


              1. I removed user page parameter


              2. in LogBookList I putted



              @In(required=false) @Out(required=false, scope=ScopeType.SESSION)
                   private User userfilter;
                   
                   
                   private static final String[] RESTRICTIONS = {
                        "logBook.action = #{logBookList.logBook.action}",
                        "logBook.user = #{userfilter}"};



              3. and in statistikListe.xhtml I made this changes



              <h:selectOneMenu value="#{userfilter}">
                   <s:selectItems value="#{distinctUsers}" var="distinctUser" label="#{distinctUser.y20gpnum}" noSelectionLabel="Alle Benutzer"/>
                   <s:convertEntity />
              </h:selectOneMenu>
              




              no more exception. But why, I don't know!!!

              • 4. Re: Problem using EntityQuery
                Feivel Frey Newbie

                I seen that someone else have had the same problem in old seam forum:
                see

                • 5. Re: Problem using EntityQuery
                  fanto black Newbie

                  When use selectOneMenu, I suggest override the equals method with business key or make sure the list in same persistent context.

                  • 6. Re: Problem using EntityQuery
                    Feivel Frey Newbie

                    Hi Shuhua,


                    I already had implementet this approach in my code. Each entity extends Standartentity wich have implemented the equals method.


                    @Entity
                    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
                    public abstract class StandardEntity  implements Serializable {
                    
                         private Long id;
                    
                         private Long version;
                         
                         @Id @GeneratedValue(strategy=GenerationType.TABLE)
                         public Long getId(){
                              return id;
                         }
                         public void setId(Long id){
                              this.id = id;
                         }
                         
                         @Version
                         @Column(name = "version")
                         public Long getVersion() {return this.version;}
                         public void setVersion(Long version) {this.version = version;}
                         
                    
                         protected String internalUUID;
                         
                         public StandardEntity(){
                              this.internalUUID = java.util.UUID.randomUUID().toString();
                         }
                    
                         @Override
                         public boolean equals(Object o) {
                              return (o == this || (o instanceof StandardEntity && internalUUID.equals(((StandardEntity)o).internalUUID)));
                         }
                         
                         public String toString() {
                              return getClass().getSimpleName() + " Id: " + getId();
                         }
                         
                         @Override
                         public int hashCode() {
                              return internalUUID.hashCode();
                         }
                         
                         @Column(name="__UUID__", unique=true, nullable=false, updatable=false, length=36)
                         public String getInternalUUID() {
                              return internalUUID;
                         }
                         public void setInternalUUID(String internalUUID) {
                              this.internalUUID = internalUUID;
                         }
                    
                    }



                    But the problem still exists.