This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes getting count of HQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "getting count of HQL query" Watch "getting count of HQL query" New topic

getting count of HQL query

Jj Dire

Joined: Jan 27, 2009
Posts: 3
I'm trying to do pagination so I need to know the count but it seems such a difficult task to find the count of a query which deferences another table. The query is

Patient POJO is

Here's my attempt at finding the count of this but no matter what it doesn't like the patient_insurance dereferning. I tried select count(*) way and this way and neither seems to work

I am totally lost and wondering what's an easy way just to get a count of a relatively simple query.

When doing select count(*) of the above query I get the "the owner fetched association was not present in the select list" error.

Thanks in advance.
Jj Dire

Joined: Jan 27, 2009
Posts: 3
found solution by using createAlias
Javid Jamae
Ranch Hand

Joined: May 14, 2008
Posts: 198
You should be able to do this with a "select count" query. What are you trying to get a count of exactly? Show the select query and the table structure (DDL).

Author: JBoss in Action,, @javidjamae on Twitter
Jj Dire

Joined: Jan 27, 2009
Posts: 3
the query is shown in my original post. If I just add select count(*) to the first query shown above, hibernate will complain. I've managed to do them all using projections.
every member is a string except date and id (date and integer).
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Hurric hurric" please check your private messages.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: getting count of HQL query