user3163179
user3163179

Reputation: 37

Counting number of element in collection using HQL

Suppose we have a class (Staff) with a Set. How can we determine the number of elements in the set, using HQL?

Upvotes: 1

Views: 892

Answers (1)

StanislavL
StanislavL

Reputation: 57411

Query query = session.createQuery(
    "select count(*) from Stuff s inner join s.set countSet  where s.id=:someId");
query.setString("someId", 123);
Long count = (Long)query.uniqueResult();

Something like this. If you post your class HQL could be corrected to reflect your names

Upvotes: 2

Related Questions