aspose file tools*
The moose likes Object Relational Mapping and the fly likes Strange Hibernate issue.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Strange Hibernate issue.. " Watch "Strange Hibernate issue.. " New topic
Author

Strange Hibernate issue..

Shekar Atmakur
Ranch Hand

Joined: Oct 24, 2003
Posts: 36
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

Joined: Dec 11, 2006
Posts: 364
If you are only interested in a total for Table A, why put Table B into the query?
Shekar Atmakur
Ranch Hand

Joined: Oct 24, 2003
Posts: 36
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

Joined: Aug 26, 2006
Posts: 4968

Would a scalar do the trick?



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

Scalar with HQL
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange Hibernate issue..
 
Similar Threads
Using JOINs
Hibernate mapping
inserts into join tables
AND/OR
SQL to HQL (Having issue in Left Outer Join)