aspose file tools*
The moose likes Object Relational Mapping and the fly likes How to get a count query of a mapped table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to get a count query of a mapped table" Watch "How to get a count query of a mapped table" New topic
Author

How to get a count query of a mapped table

Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
How can I get a count query of a mapped table?

I need to count the number of rows given a few parametres.



The value I want returned is a number not any mapped object or list. The number of rows where the table attributes corresponds to the param values.

I am using Spring and its hibernateTemplate with Hibernate mappings
[ January 16, 2008: Message edited by: Sverre Moe ]
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
See the aggregate functions in the Hibernate Reference.
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Originally posted by Edvins Reisons:
See the aggregate functions in the Hibernate Reference.


That was allready clear. But, I had to create a query in the mapping file and access it through findByNamedQueryAndNamedParam. Is the no better way to get a count? If not I could just use JDBC to get the count in stead of going through Hibernate.
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Have you tried making that HQL count a named query and accessing it with that long-named method?
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Originally posted by Edvins Reisons:
Have you tried making that HQL count a named query and accessing it with that long-named method?


Yes, and it worked. I was just hoping I could use the mapped object in some way instead of creating a named query. Or perhaps Hibernate is not meant to be that way. That all other than getting a complete object (one row) of data or a list of them should be accessed through named queries. Such as queries with mathematical operations.

Well well. All is good.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get a count query of a mapped table
 
Similar Threads
JDBC & JSP
how to write this query... count, unique, ??
EJB-QL count query????
Retrieving Count (*) value
count number of coulmns in table?