views:

549

answers:

1

Using JPA query language, how do I determine the size (number of rows) in an entity (table)?

+4  A: 

Use the count aggregate function:

EntityManager em = ...
Query q = em.createQuery ("SELECT count(x) FROM Magazine x");
Number result = (Number) q.getSingleResult ();
Joshua