• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query column number mismatch

 
Gyula Klinszky
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gyula Klinszky
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic