Possible Duplicate:
How do we count rows using Hibernate?
I want count number of records by criteria in database.
I try use next query
String queryString = "SELECT Count(*) FROM my_table";
Query query = entityManager.createNativeQuery(queryString);
but there is no method to execute this Query query
and get result.
I know, that I can count records using
String queryString = "SELECT * FROM my_table";
Query query = entityManager.createNativeQuery(queryString);
query.getResultList().size();
so question, is query with Count(*)
more performance, and if yes
, then how can I execute query with Count(*)
?