I have Java EE application, where I have list of groups. I want to display number of items in every group, so I do:
SELECT COUNT(p) FROM Product p WHERE LOWER(p.group) = LOWER(:group)
Group is plain String.
Problem is when I have 50+ groups, time to load page is about 10s, which is unacceptable. When I remove counting time drops to ~1s. How can I optimize/cache this?
My first idea was to use EJB singleton to keep counts locally and refresh them with EJB timer.
I’m using glassfish v3, eclipselink and oracle 10g database on same machine.
I’m using cache in eclipselink, but it seems not to cache count queries.
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.cache.size.default" value="500"/>
How about selecting all groups and associated counts in one query? This is not a JPA answer, but a plain SQL one: