-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Hibern8Ide submits malformed SQL to the database!
PostPosted: Sat Nov 27, 2004 12:11 am 
Newbie

Joined: Tue Oct 26, 2004 2:12 am
Posts: 11
Hibernate version:2.1.7 or 2.1.6 (tried both)

Mapping documents:Middlegen 2.1

Name and version of the database you are using:Firebird 1.5.1

Hi, I have a table called 'Collections' and another called 'BorrowerTypes'. There is an 'overrides' table (called Overrides_Collectns_Brwrtypes) that associates the two and is a many-many. i.e There can be an override between one collection and several borrower types. (Of course these tables have been renamed by middlegen.)

I want to list the pk of all Collection rows, so in HQL I do this:
Code:
select c.collectionSn from Collection c

which gives me 51 records, which is correct.

I also want to indicate in the results whether (for each row) there is 0 or more 'overrides' records. This could either be a count of 0-n or a List of 0-n records, it doesn't matter.

So I modified the HQL:
Code:
select c.collectionSn, count(c.overridesCollectnsBrwrtypes) from Collection c


However I get the error
Quote:
Column unknown C.OVERRIDESCOLLECTNSBRWRTYPES

Examining the SQL in the hibern8ide console, I see
Code:
[java] Hibernate: select collection0_.COLLECTION_SN as x0_0_, count(c.overridesCollectnsBrwrtypes) as x1_0_ from COLLECTIONS collection0_


The column c.overridesCollectnsBrwrtypes is a hibernate representation of my table; it seems that either hibern8ide or hibernate has not generated the correct SQL code.

Can anyone tell if the query should be done differently?
Could there be some sort of mapping error (in one of my mapping files)?

Regardless, hibernate should not be submitting this malformed SQL to the database - it is clearly using a hibernate-generated field name whose name differs from those in the database. It also hasn't resolved the relationship that exists between the Collections and Overrides_Collectns_Brwrtypes tables (i.e some sort of join).

TIA
PS. Clutching at straws, this also fails (same type of error):
Code:
select c.collectionSn, count(ocb.collectionSn) from Collection c join c.overridesCollectnsBrwrtypes ocb


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 3:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
First: Hibern8IDE just uses Hibernate to execute HQL so it doesn't do any sql-generation of it's own.

Secondly: You are using a aggregate function in the select clause which when applied to a collection should be done (as written in the docs):

Code:
select cat, count( elements(cat.kittens) )
from eg.Cat cat group by cat


Read: http://www.hibernate.org/hib_docs/refer ... ggregation

;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 6:04 pm 
Newbie

Joined: Tue Oct 26, 2004 2:12 am
Posts: 11
max wrote:
First: Hibern8IDE just uses Hibernate to execute HQL so it doesn't do any sql-generation of it's own.

Good to hear, I wasn't sure, but was hopeful that the work was passed on to hibernate ;-)

max wrote:
Secondly: You are using a aggregate function in the select clause which when applied to a collection should be done (as written in the docs):

Code:
select cat, count( elements(cat.kittens) )
from eg.Cat cat group by cat


Read: http://www.hibernate.org/hib_docs/refer ... ggregation

;)

Yes, I've read the docs, and that's what I was originally trying. But I was getting errors like 'elements is not a property of xxx' (sorry, cannot remember the exact message, but can follow up tomorrow at the office).

I discussed this problem a fair bit on IRC, tried many things and the final suggestion was to post a message here :)
Like I say, even if the HQL is malformed, I'm suprised that hibernate could generate SQL which contains hibernate-generated property names.

Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 6:11 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The parser in Hibernate 2.x doesn't have the capability to detect the correct syntax. The LL(K) lexer/parser/parser combo in Hibernate 3.x is an excellent new feature done by Joshua Davis. We'll have both systems in Hibernate 3.x and you can switch back if there are any issues (we have thousands of regression tests, so this will hopefully not be neccessary).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
Like I say, even if the HQL is malformed, I'm suprised that hibernate could generate SQL which contains hibernate-generated property names.


Not that big a surprise since the logic is that if hql doesn't recognize something as a keyword or hql-identifier it will assume it is some sql function/identifier which can be quite usefull ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 27, 2004 7:12 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, yes thats by design. I hadn't read the original posting.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.