openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "C N Davies" <>
Subject Summing in OpenJPA 1.2.x
Date Fri, 08 Jan 2010 15:39:56 GMT


I have a load of  entities persisted in my tables, now I need to sum some of
the values in these tables to come up some totals.   Previously I don't it
like so:


select o from Account where ..


Then process each of the objects to get their values and add them all up to
come up with the total value of all these records. It's pretty slow since
there are hundreds of thousand of records and pretty inefficient of course.
In SQL I would use something like this:


Select Name, sum(total) from account


But how can I do this in JPA, since the return type of the query is expected
to by an entity. I guess I could define a new entity which has Name and
Total members and then use the native query functionality and map that to
returned results.  Is this the best approach or is there a better way to do


Thanks for any pointers!





  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message