I am wondering how to effectively use an EJB query in the following situation.
I have 2 tables. Each table has a corresponding @Entity java class. | TableA | --------- | int tableAPrimaryKey | varchar(20) tableAField | ...etc, plus many more fields | | TableB | --------- | int tableBPrimaryKey | int tableAForeignKey | varchar(20) tableBField | ...etc, plus many more fields | I would like to run a query that gets each row from Table A, and a count from Table B (dependant on tableAForeignKey). So for each row my html output would look something like this: "tableAField1", "tableAField2", "tableBCount" Using EJB, I can get each row of TableA by running: | Query q = em.createQuery("from TableA o "); | return q.getResultList(); | Using EJB, I can get a count for each row of TableA from TableB | Query q = em.createQuery( | "select count(o) " + | "from TableB o " + | "where o.tableAForeignKey = :currentRow" | ); | Is there a better way to do this using EJB? Looping through each result of Table A and executing a count query seems pretty inefficient. The correct way seems to be to create a native query and manually build all these objects. This is extremely tedious as there are a lot of columns in both tables that are needed. Are there any suggestions of a better way to do this using EJB? View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3919354#3919354 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3919354 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user