File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Query column number mismatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Query column number mismatch" Watch "Hibernate Query column number mismatch" New topic
Author

Hibernate Query column number mismatch

Gyula Klinszky
Greenhorn

Joined: Jan 20, 2003
Posts: 27
Hi people,

I encountered a strange problem while doing a supposedly simple Hibernate query. I defined 3 columns in the HQL, according to the Hibernate debug, the created SQL also contains 3 columns, but at calling query.list() Hibernate throws an exception saying that it is missing one column. Calling query.getReturnTypes revealed that the query expected a 4th column containing an integer. I am stuck, would welcome an ideas, or pointers on the topic

Here is the basic code:



The DB hierarchy is quite simple, a Person can have multiple Phones, and a PhoneBill is a specific phone's cost data for a given period (BillingPeriod object).
Gyula Klinszky
Greenhorn

Joined: Jan 20, 2003
Posts: 27
Hi all,

an update to the topic opener: I changed the sum calculation in the query, removing the multiplication ( sum(xpb.netamount) ), and the exception was gone, so the problem is linked to the "complex" sum command using 2 fields multiplication. Is it familiar to anyone ?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
just a guess:

looks like you'r translating from sql...

if you map Person and Phone as a parent/child relatioship your hql will be much simpler

take a look at docs that ship with install - there they have several parent/child examples

hope this helps


java amateur
Gyula Klinszky
Greenhorn

Joined: Jan 20, 2003
Posts: 27
Originally posted by miguel lisboa:
just a guess:

looks like you'r translating from sql...

if you map Person and Phone as a parent/child relatioship your hql will be much simpler

take a look at docs that ship with install - there they have several parent/child examples

hope this helps


Yes, you are right, that the query is closer to SQL than to HQL, I need practice with it
Still, rewriting it did not help:
It seems that my Hibernate (2.1.8) has a bug evaluating queries containing complex aggregates, it creates the right SQL from the HQL statement, but at the same time it expects one more column returned than the actual number of them. Anyone had similar experiences ?
Gyula Klinszky
Greenhorn

Joined: Jan 20, 2003
Posts: 27
Hmm, I found the answer, this is (was) a bug in Hibernate, and according to their bug tracking system, it is corrected in version 3.0.
See:
Bug item

Too bad I cannot upgrade current in my project to 3.0
 
 
subject: Hibernate Query column number mismatch