Also, if I did it the EJB way that I showed in my previous post, that would require me to create an
@Transient int countin MyTableA's java file to store the count.
Also, what if I wanted to sort the results by the count? This would require a lot more work instead of a simple order by clause.
Is there a better way to restructure the Entity classes? Is there a better way to nest EJB queries?
Maybe I should create a view in the database and create a POJO from that?
I'm thinking that would be my best bet.
There are two solutions I can think of. The first side-steps an EJB query.
One of class A's attributes will be a collections of some sort of class B. Simply get an instance of class A by primary key, get an instance of the collection of Bs and do a bees.size().
The second is to do a join. Something like select ab from A as a join a.b as ab where a.PrimaryKey=PK and then again a size() on ab.