• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Strange Hibernate issue..

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ,
I am getting a strange issue in Hibernate and i hope someone can help me resolve it. It may be because i am still new to Hibernate, but i do need a little nudge.
Basically what is happening is that the query that is provide to Hibernate for execution changes automatically. Here is a dummied down example

Input HQL: SELECT SUM(A.AMOUNT) FROM TABLEA A, TABLEB B WHERE TABLEA.ID=TABLEB.ID AND TABLEA.NAME= 'XYZ'

Now what I am expecting out of this query is only a single Object which i can easily typecast into a integer. But what i observed was that the query was being translated into the following by Hibernate.

Output HQL: SELECT A.NAME,A.AMOUNT,A.COL2,B.COL1,B.COL2,BB.COL3 FROM TABLEA A, TABLEB B WHERE TABLEA.ID=TABLEB.ID AND TABLEA.NAME= 'XYZ'

So basically what i getting is the entire row is the result set. when i expecting only the sum.

Hoping somebody can help here.

Gracias,
Shekar
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are only interested in a total for Table A, why put Table B into the query?
 
Shekar Atmakur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thank for the reply. I only meant to have a join between two tables.I actually meant the following

Input HQL: SELECT SUM(A.AMOUNT) FROM TABLEA A, TABLEB B WHERE TABLEA.ID=TABLEB.ID AND TABLEB.ID= 123



But my core problem, is when i provide an input query that should give me a simple sum resonse, What is am getting is an ArrayList of all the Objects within the Query.

Once again. appricitate your help.
 
author and cow tipper
Posts: 5006
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would a scalar do the trick?



Here's the site I stole the code off of:

Scalar with HQL
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic