• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to get a count query of a mapped table

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the aggregate functions in the Hibernate Reference.
 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried making that HQL count a named query and accessing it with that long-named method?
 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
It's a tiny ad. At least, that's what she said.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic