-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Count number of references
PostPosted: Thu Jul 31, 2008 11:12 am 
Newbie

Joined: Thu Jul 31, 2008 10:51 am
Posts: 3
Location: Wuppertal, Germany
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.