2 Replies Latest reply on Sep 10, 2008 8:42 AM by dhinojosa

    Query Multiple Objects for a browser?

    mo2p

      I have a problem i can't solve at the moment...and i have just a ugly solution for it that works not as it was supposed...


      i have to entitys that are in releation to each other and i wanted to build a browser over their releational information...


      promotions and articles ..each promotion can have one article with a price ...


      goal was it to show a browser over all promotions with their articles and prices...


      i failed a building a query that pulled both objects at the same time... is their a way...and then how to display they in the same row?


      my ugly solution ...that is really bad...


                List<Promotion> results = em.createQuery("select p from Promotion p,Article a " +
                                          "where p.article = a " +
                                          "and lower(p.name) like #{pattern}")
                          .setMaxResults(pageSize + 1)
                          .setFirstResult(page * pageSize)
                          .getResultList();
      
                List<Article> resultArticle = em
                .createQuery("select a from Promotion p,Article a " +
                                "where p.article = a " +
                                "and lower(p.name) like #{pattern}")
                .setMaxResults(pageSize + 1)
                .setFirstResult(page * pageSize)
                .getResultList();
      



      but even with this solution i run in the problem to display them in the JSF ...



                                    <h:outputText value="No Promotions Found" rendered="#{promotions != null and promotions.rowCount==0}" />
                                    <h:dataTable id="promotions" value="#{promotions}" var="pro" rendered="#{promotions.rowCount>0}">
                                         <h:column>
                                              <f:facet name="header">Name</f:facet>
                                                   #{pro.name}
      ...
      ...
      ...
      ...
                                    <h:dataTable id="articles" value="#{articles}" var="art" rendered="#{articles.rowCount>0}">
                                         <h:column>
                                              <f:facet name="header">Name</f:facet>
                                                   #{art.name}
      
      



      i wanted the information in the same table with out the separation how can i accomplish that..


      im still learning this and putted many hours already in it...but i don't come to an good solution..have i to build a special object for that...?


      plz help ..i bang my head on the keyboard already to loong

        • 1. Re: Query Multiple Objects for a browser?
          dhinojosa



          but even with this solution i run in the problem to display them in the JSF ...

          So what does that mean?  Are you getting an exception? nothing? bad results? an itch? ;)

          • 2. Re: Query Multiple Objects for a browser?
            dhinojosa

            Let take a stretch here and assume you are trying to do the following... You don't need to go that far in your QL.



                      List<Promotion> results = em.createQuery("select p from Promotion" +
                                                "where lower(p.name) like #{pattern}")
                                .setMaxResults(pageSize + 1)
                                .setFirstResult(page * pageSize)
                                .getResultList();
                    
            


            then in your pages:


            <h:outputText value="No Promotions Found" rendered="#{promotions != null and promotions.rowCount==0}" />
                                          <h:dataTable id="promotions" value="#{promotions}" var="pro" rendered="#{promotions.rowCount>0}">
                                               <h:column>
                                                    <f:facet name="header">Name</f:facet>
                                                         #{pro.name}
            ...
            ...
            ...
            ...
                                          <h:dataTable id="articles" value="#{promotion.articles}" var="art" rendered="#{promotion.articles.rowCount>0}">
                                               <h:column>
                                                    <f:facet name="header">Name</f:facet>
                                                         #{art.name}
            
            



            Let us know if that's what you are looking for.