Query Multiple Objects for a browser?
mo2p Sep 8, 2008 9:53 PMI 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