This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes GWT and JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "GWT and JPA" Watch "GWT and JPA" New topic


Debapriya Dutta

Joined: Oct 24, 2012
Posts: 1
We have two entities:
Entity A and Entity B. Entity B has a foreign key from Entity A. In the client we have a celltable populated with data from Entity A and there is a column that reference how many Entity B elements exist for each Entity A row.

Is there an easy way to fetch the count of entity B records for each entity A and then have it be a sortable column?

Thanks in advance. I am sorry if the question is a little vague - it's kind of sensitive work information that I am not sure I can explain in too great a detail.

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10836

From the UI perspective, it does not matter how your data is generated, so I will move this question to a more appropriate forum for you.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
There are two ways,

1 - just access A's collection of B's and get the size. To optimize how the bs are loaded you can use join fetching, or batch fetching.

2 - Use a count in your query, "Select a, count(b) from A a join b where ..."

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
wood burning stoves
subject: GWT and JPA
jQuery in Action, 3rd edition