4 Replies Latest reply on Mar 19, 2009 2:05 AM by scott duke

    Join on Ejbql within EntityQuery

    scott duke Novice

      I have 2 entities: Uzer and Phone. Later, I plan on adding a third called Address. Uzer entity have a one-to-many relationship to the Phone entity. Address will have the same relationship.


      The problem is with my UzerList. I want to be able to search on the company name, user name or phone number. Later I will add the address on this search. Within the UzerList.java, my Ejbql is:



      this.setEjbql("select uzer from Uzer uzer left join uzer.phones phone");
      



      When I add a new user with say 3 phone numbers, on my UzerList.xhtml I use rich:dataTable, with only the columns Company and Name, it appears 3 times.


      If I try to add the phone number to the xhtml, I receive a Property 'phoneNumber' not found on type com.artwork.entity.Uzer. This is understandable, since phone number is not directly associated to the Uzer entity.


      My question is this...


      How can I add the phone number to the display without adding another table on the column? Is this even possible or do I need to create a different type of query?



        • 1. Re: Join on Ejbql within EntityQuery
          serkan koyun Newbie
          This is my usage:

          Entity Query:
          String EJBQL = "select ggf030,vggv002 from Ggf030 ggf030,Vggv002 vggv002 where "
                              + " ggf030.g030item=vggv002.item)  ";

          Datatable:
          <rich:dataTable id="ggf030List"  var="_ggf030" rowKeyVar="rowKey" value="#{ggf030List.resultList}">
          <!--This Columm from first entity -->
          <h:column>
          <f:facet name="header"> Item Code</f:facet>
          <h:outputText value="#{_ggf030[0].g030item}" />
          </h:column>

          <!-- and this is from second -->
          <h:column>
          <f:facet name="header"> Item Desc.</f:facet>
          <h:outputText value="#{_ggf030[1].itemDesc}" />
          </h:column>


          • 2. Re: Join on Ejbql within EntityQuery
            scott duke Novice

            Thanks for your reply. However, it looks like you are using a one-to-one relationship, whereas, I am using a one-to-many relationship. I did try the html as you described and received the following error.



            09:32:06,468 ERROR [STDERR] Mar 18, 2009 9:32:06 AM com.sun.facelets.FaceletViewHandler handleRenderException
            SEVERE: Error Rendering View[/UzerList.xhtml]
            java.lang.NumberFormatException: For input string: "id"
                 at java.lang.NumberFormatException.forInputString(Unknown Source)
                 at java.lang.Integer.parseInt(Unknown Source)
                 at java.lang.Integer.parseInt(Unknown Source)
                 at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:153)
                 at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:45)
                 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.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                 at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                 at javax.faces.component.UIParameter.getValue(UIParameter.java:167)
                 at org.jboss.seam.ui.util.ViewUrlBuilder.addParameter(ViewUrlBuilder.java:43)
                 at org.jboss.seam.ui.component.UISeamCommandBase.getUrl(UISeamCommandBase.java:56)
                 at org.jboss.seam.ui.renderkit.LinkRendererBase.doEncodeBegin(LinkRendererBase.java:26)
                 at org.jboss.seam.ui.util.cdk.RendererBase.encodeBegin(RendererBase.java:79)
                 at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
                 at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:280)
                 at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                 at org.richfaces.renderkit.AbstractTableRenderer.encodeOneRow(AbstractTableRenderer.java:392)
                 at org.richfaces.renderkit.AbstractRowsRenderer.process(AbstractRowsRenderer.java:86)
                 at org.ajax4jsf.model.SequenceDataModel.walk(SequenceDataModel.java:101)
                 at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:1151)
                 at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:106)
                 at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:91)
                 at org.richfaces.renderkit.AbstractTableRenderer.encodeTBody(AbstractTableRenderer.java:76)
                 at org.richfaces.renderkit.AbstractTableRenderer.encodeChildren(AbstractTableRenderer.java:83)
                 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                 at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                 at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                 at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
                 at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                 at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
                 at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
                 at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
                 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                 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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                 at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                 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:178)
                 at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                 at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                 at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                 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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                 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:182)
                 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(Unknown Source)
            



            My SQL in the log file is:


                select
                    uzer0_.id as id1_0_,
                    phones1_.id as id0_1_,
                    uzer0_.name as name1_0_,
                    uzer0_.version as version1_0_,
                    uzer0_.hashedPassword as hashedPa4_1_0_,
                    uzer0_.company as company1_0_,
                    uzer0_.email as email1_0_,
                    uzer0_.uzerSince as uzerSince1_0_,
                    phones1_.type as type0_1_,
                    phones1_.version as version0_1_,
                    phones1_.phoneNumber as phoneNum4_0_1_,
                    phones1_.ext as ext0_1_,
                    phones1_.createdOn as createdOn0_1_,
                    phones1_.uzerId as uzerId0_1_ 
                from
                    uzer uzer0_ 
                left outer join
                    Phone phones1_ 
                        on uzer0_.id=phones1_.uzerId 
                order by
                    uzer0_.name asc limit ?
            



            And my xhtml part within the dataTable looks like:


                        <rich:dataTable id="uzerList" 
                                       var="_uzer"
                                   value="#{uzerList.resultList}" 
                                 rendered="#{not empty uzerList.resultList}">
                           
                         <h:column>
                             <f:facet name="header">
                                 <a4j:htmlCommandLink styleClass="columnHeader" reRender="uzerList"
                                                   value="Company #{uzerList.order=='company asc' ? messages.down : ( uzerList.order=='company desc' ? messages.up : '' )}">
                                     <f:param name="uzerListOrder" value="#{uzerList.order=='company asc' ? 'company desc' : 'company asc'}"/>
                                 </a4j:htmlCommandLink>
                             </f:facet>
                             #{_uzer[0].company}
                         </h:column>   
            
                         <h:column>
                             <f:facet name="header">
                                 <a4j:htmlCommandLink styleClass="columnHeader" reRender="uzerList"
                                                  value="Name #{uzerList.order=='name asc' ? messages.down : ( uzerList.order=='name desc' ? messages.up : '' )}">
                                     <f:param name="uzerListOrder" value="#{uzerList.order=='name asc' ? 'name desc' : 'name asc'}"/>
                                 </a4j:htmlCommandLink>
                             </f:facet>
                             #{_uzer[0].name}
                         </h:column>
                         
                             <h:column>
                             <f:facet name="header">
                                 <a4j:htmlCommandLink styleClass="columnHeader" reRender="uzerList"
                                                  value="Phone #{uzerList.order=='phones.phoneNumber asc' ? messages.down : ( uzerList.order=='phones.phoneNumber desc' ? messages.up : '' )}">
                                     <f:param name="uzerListOrder" value="#{uzerList.order=='phones.phoneNumber asc' ? 'phones.phoneNumber desc' : 'phones.phoneNumber asc'}"/>
                                 </a4j:htmlCommandLink>
                             </f:facet>
                             #{_uzer[1].phoneNumber}
                         </h:column>
                                           
                         <h:column>
                             <f:facet name="header">Action</f:facet>
                             <s:link view="/#{empty from ? 'Uzer' : from}.xhtml" 
                                    value="Select" 
                                       id="uzer"
                                   propagation="none">                           
                                  <f:param name="uzerFrom" 
                                         value="#{uzerFrom}"/>
                                 <f:param name="uzerId" 
                                         value="#{_uzer.id}"/>
                             </s:link>
                         </h:column>
                                  
                        </rich:dataTable>
            



            • 3. Re: Join on Ejbql within EntityQuery
              serkan koyun Newbie
              i think your mistake is     value="#{_uzer.id}"  :) it must be    value="#{_uzer[0].id}"    or  value="#{_uzer[1].id}"

              <blockquote>
                           <h:column>
                               <f:facet name="header">Action</f:facet>
                               <s:link view="/#{empty from ? 'Uzer' : from}.xhtml"
                                      value="Select"
                                         id="uzer"
                                     propagation="none">                          
                                    <f:param name="uzerFrom"
                                           value="#{uzerFrom}"/>
                                   <f:param name="uzerId"
                                           value="#{_uzer.id}"/>
                               </s:link>
                           </h:column>
                          </rich:dataTable>
              </blockquote>