Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange Hibernate issue..

 
Shekar Atmakur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would a scalar do the trick?



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

Scalar with HQL
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic