2 Replies Latest reply on Nov 8, 2009 10:55 PM by nmatrix nmatrix

    Frustrations with enityquery multi-entity properties query

    nmatrix nmatrix Newbie
      *Sigh*

      After my previous battles with EntityQuery with my book "Seam In Action".  I thought I had EnityQuery figured out but unfortunately the javax.servlet.ServletException says other wise.  I've re-read chapter 10 of Seam in Action to try and emulate the description on Page 458  "the hierarchial example object that can be fed into the join query . . ".  Not so hard right?  Well This is what I did for my components.xml just like in Seam in Action.

      ...
      <component class="com.domain.exoshellcms.entity.ExoshellUsers" name="userExample"/>
      <component class="com.domain.exoshellcms.entity.ExoshellRoles" name="roleExample"/>
      <component class="com.domain.exoshellcms.entity.ExoshellModules" name="moduleExample"/>
      <component class="com.domain.exoshellcms.entity.ExoshellUserRoles"
        name="userRolesExample" scope="CONVERSATION">
        <property name="exoshellUsers">#{userExample}</property>
        <property name="exoshellRoles">#{roleExample}</property>
        <property name="exoshellModules>#{moduleExample}</property>
      </component>
      ...


      the entity relationship I believe is similar to what the round -> golfer, round -> teeset relationship is like in the book Seam in action.  For my particular case it is:

                         ExoshellUsers  ExoshellRoles   ExoshellModules  0 to 1 entities
                                              \                |                /                                         
                                               \               |              /
                                                 \             |            /
                                                 ExoshellUserRoles   0 to 1-n    entity
                                                        + userRolesId
                                                        + ExoshellUsers
                                                        + ExoshellRoles
                                                        + ExoshellModules


      It seems that no matter what, the entity exoshellUserRoles cannot access it's entity properties exoshellUsers etc.  Even if I do a eager fetch in a entity query.  Any insight as to what I'm missing or overlooking would be greatly appreciated.



      and my supporting session bean:

      @Name("exoshellUserRolesList")
      @Scope(ScopeType.SESSION)
      public class ExoshellUserRolesList extends EntityQuery<ExoshellUserRoles> {
           /* UNABLE TO GET RESTRICTIONS TO WORK WITHOUT POINTING TO NULL PARENT OBJECT I.E. exoshellUsers, exoshellRoles or exoshellModules */
           private static final String[] RESTRICTIONS = {
                "lower(exoshellUserRoles.exoshellUsers.username) like concat(lower(#{userRolesExample.exoshellUsers.username}),'%')"
           };

           private ExoshellUserRoles exoshellUserRoles = new ExoshellUserRoles();  
           private String queryString = new String("select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles inner join fetch exoshellUserRoles.exoshellUsers exoshellUsers");

           public ExoshellUserRolesList() {
           setEjbql(queryString);
           }
           
           @Override
           public String getEjbql() {
                return queryString;
           }

           public ExoshellUserRoles getExoshellUserRoles() {
                return exoshellUserRoles;
           }

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

           @Override
           public String getOrder() {
                return new String("exoshellUserRoles.exoshellUsers.username asc");
           }

      }


      The corresponding interface frontend:
      ....
        <h:inputText id="userRoleName" value="#{userRolesExample.exoshellUsers.username}">
      ....

      inputing a username for entityquery search throws the following error:

      21:54:48,942 ERROR [ExceptionFilter] exception root cause
      javax.el.PropertyNotFoundException: /admin/ExoshellUserRolesEdit.xhtml @339,99 value="#{userRolesExample.exoshellUsers.username}": Target Unreachable, identifier 'userRolesExample' resolved to null
           at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
           at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92) . . .


      For EL expressions and entity query I've also tried:

      1.  exoshellUserRolesList.exoshellUsers.username
          
           "select exoshellUserRoles from ExoshellUserRoles exoshellUserRoles  join fetch exoshellUserRoles.exoshellUsers exoshellUsers"

      with error:

      Exception during request processing:
      Caused by javax.servlet.ServletException with message: "/admin/ExoshellUserRolesEdit.xhtml @339,122 value="#{exoshellUserRolesList.exoshellUserRoles.exoshellUsers.username}": Target Unreachable, 'exoshellUsers' returned null on 'com.domain.exoshellcms.entity.ExoshellUserRoles'"
        • 1. Re: Frustrations with enityquery multi-entity properties query
          nmatrix nmatrix Newbie
          Hello Everyone,

          Made some progress with this issue with help from this thread http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4068892#4068892  .  The information from that thread gave me some ideas on how to resolve the null target issue with code like below with the constructor.:

          public ExoshellUserRoles getExoshellUserRoles() {
                     if (exoshellUserRoles.getExoshellUsers() == null){
                          exoshellUserRoles.setExoshellUsers(exoshellUsersHome.getInstance());
                     } 
                    return exoshellUserRoles;
               }

          And injecting a home entity to set/instantiate exoshellUserRoles.  ExoshellUsers property

               @In
               private ExoshellUsersHome exoshellUsersHome;

          I've made some progress but when I enter a search term in the inputext field to begin search query, the data table refreshes but the datatable remains the same minus the datascroller.  But when I clear the text input field to do a blank search (a wildcard to search everything ) I get the following error:

          3:31:14,803 INFO  [STDOUT] Hibernate:
              select
                  exoshellus0_.user_roles_id as user1_89_,
                  exoshellus0_.module_id as module2_89_,
                  exoshellus0_.role_id as role3_89_,
                  exoshellus0_.user_id as user4_89_
              from
                  public.exoshell_user_roles exoshellus0_,
                  public.exoshell_users exoshellus1_
              where
                  exoshellus0_.user_id=exoshellus1_.user_id
                  and (
                      lower(exoshellus1_.username) like (lower(?)||'%')
                  )
              order by
                  exoshellus0_.user_roles_id asc
          00:57:10,461 WARN  [lifecycle] javax.el.ELException: /admin/ExoshellUserRolesEdit.xhtml @364,70 rendered="#{empty exoshellUserRolesList.resultList}": Error reading 'resultList' on type com.domain.exoshellcms.session.ExoshellUserRolesList_$$_javassist_415
          00:57:11,386 ERROR [viewhandler] Error Rendering View[/admin/ExoshellUserRolesEdit.xhtml]
          javax.faces.FacesException: javax.el.ELException: /admin/ExoshellUserRolesEdit.xhtml @364,70 rendered="#{empty exoshellUserRolesList.resultList}": Error reading 'resultList' on type com.domain.exoshellcms.session.ExoshellUserRolesList_$$_javassist_415
               at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:393)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:94)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:86)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:134)
               at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:122)
               at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:553)
               at org.ajax4jsf.component.AjaxViewRoot$4.invokeRoot(AjaxViewRoot.java:384)
               at org.ajax4jsf.context.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:56)
               at org.ajax4jsf.context.AjaxContextImpl.invokeOnRegionOrRoot(AjaxContextImpl.java:170)
               at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:401)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
               at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
               at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
               at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
               at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
               at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:307)
               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.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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
               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:173)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
               at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
               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:241)
               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:447)
               at java.lang.Thread.run(Thread.java:619)
          Caused by: javax.el.ELException: /admin/ExoshellUserRolesEdit.xhtml @364,70 rendered="#{empty exoshellUserRolesList.resultList}": Error reading 'resultList' on type com.domain.exoshellcms.session.ExoshellUserRolesList_$$_javassist_415
               at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
               at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:390)
               ... 65 more
          Caused by: java.lang.IllegalStateException: EntityManager is closed
               at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:66)
               at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:455)
               at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:450)
               at org.jboss.seam.persistence.EntityManagerProxy.joinTransaction(EntityManagerProxy.java:120)
               at org.jboss.seam.transaction.AbstractUserTransaction.enlist(AbstractUserTransaction.java:73)
               at org.jboss.seam.framework.EntityQuery.joinTransaction(EntityQuery.java:230)
               at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:173)
               at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:73)
               at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:65)
               at com.domain.exoshellcms.session.ExoshellUserRolesList.getResultList(ExoshellUserRolesList.java:41)
               at sun.reflect.GeneratedMethodAccessor18921.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
               at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
               at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
               at org.jboss.seam.util.Work.workInTransaction(Work.java:41)
               at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
               at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
               at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
               at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
               at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
               at com.domain.exoshellcms.session.ExoshellUserRolesList_$$_javassist_415.getResultList(ExoshellUserRolesList_$$_javassist_415.java)
               at sun.reflect.GeneratedMethodAccessor18920.invoke(Unknown Source)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
               at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
               at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
               at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
               at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
               at org.jboss.el.parser.AstEmpty.getValue(AstEmpty.java:29)
               at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
               at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
               ... 66 more

          • 2. Re: Frustrations with enityquery multi-entity properties query
            nmatrix nmatrix Newbie
            Hello Everyone, 

            Issue resolved, I used this previous posting for reference on how to fix the "the target is unreachable" error.
            http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4068892#4068892

            I hope this helps other users out there.