I was trying to find the count of references to a specific entity.
I've got the following model:
- Client (the entity I want to count the references to)
- ClientBased (a MappedSuperclass defining the reference to Client)
- several entities extending ClientBased
here's the JPA-query I've used:
SELECT COUNT(all c)
FROM foo.bar.ClientBased c
WHERE c.client = ?1
HAVING COUNT(all c) > 0
When executing this query, it will result in one row per entity having 1 or more references to the specified client. This would do the job, but
was unexpected, so I tried to limit the result-set with query.setMaxResults(1), as the result should only be used to test whether there are any references or not.
But after doing so, calling getSingleResult() a javax.persistence.NoResultException comes up. A list returned by getResultList() is empty.
Beforehands an info-message is logged: "[HQLQueryPlan] firstResult/maxResults specified on polymorphic query; applying in memory!" followed by a series of queries (one per entity).
Could anybody give me a hint the problem is sitting in front of the monitor, please !?
Used hibernate packages:
hibernate 3.2.5.ga
hibernate entitymanager 3.3.1.ga
hibernate annotations 3.0.0.ga
Best regards,
Florian
|