13

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

Michael Myers
  • 188,989
  • 46
  • 291
  • 292
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257

1 Answers1

23

Use the count aggregate function:

EntityManager em = ...
Query q = em.createQuery ("SELECT count(x) FROM Magazine x");
Number result = (Number) q.getSingleResult ();
Joshua
  • 26,234
  • 22
  • 77
  • 106