-->
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.  [ 5 posts ] 
Author Message
 Post subject: HQL help: possible to "select NULL as ..."?
PostPosted: Tue Apr 08, 2008 9:39 am 
Newbie

Joined: Tue Jun 12, 2007 12:36 pm
Posts: 6
Hi, I am trying to run the following HQL through Hibernate:

"select distinct col1, null as col2, col3 from table1"

However, this throws the error:
unexpected AST node: NULL

Is there some way to always get back NULL for a column?

Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 9:48 am 
Newbie

Joined: Wed Feb 01, 2006 10:45 am
Posts: 18
Location: Salzburg, Austria
have you tried just ...

Code:
select distinct col1, null, col3 from table1

_________________
greetings,
kris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 10:06 am 
Newbie

Joined: Tue Jun 12, 2007 12:36 pm
Posts: 6
Yep, thats even worse... it returns data that isn't correct.


If I have a table with 1 row, 3 cols:

COL1 | COL2 | COL3
----------------------
'val1' | 'val2' | 'val3'


And I run:
"select COL1, NULL, COL3 from TABLE1"

What I want to get back is: Object[3]{"val1", null, "val3"}

But what I get is: Object[1]{"val1"}

Likewise, if I said "select COL1, COL2, NULL from TABLE1"
I get back: Object[2]{"val1", val2"}

Hibernate seems to just stop processing columns once it hits a NULL in the statement, which is why I was going to try to alias them instead. Interestingly, the above does not throw an error, even though it seems like it should.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 10:14 am 
Newbie

Joined: Tue Jun 12, 2007 12:36 pm
Posts: 6
oh, it might also be worth mentioning that if I do:
"select COL1, 'foo' as COL2, COL3 from TABLE1"

Then I do get back: Object[3]{"val1", "foo", "val3"}

Also, if I try:
"select COL1, NonExistantCOL, COL3 from TABLE1"

Then it does throw an exception saying it cant find 'NonExistantCOL'. So it does seem to properly parse the NULL as something and tries to run.

Maybe I'll start debugging into the Hibernate code and see if I can find anything else...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 3:26 pm 
Newbie

Joined: Tue Jun 12, 2007 12:36 pm
Posts: 6
The plot thickens... From my debugging I've found that in SessionImpl.list() it calls getHQLQueryPlan() to get a new instance of an HQLQueryPlan for the statement.

If I pass in my "select col1, null, col3 from table1" hql string to SessionImpl.list(), that gets passed into the HQLQueryPlan, and it puts together a plan for the query "select col1, col3 from table1" (as the actual SQL query). So it isn't parsing the query correctly.

Then, at some point further in, it also incorrectly processes the ResultSet, and only grabs the first column to return in an Object[1]{val1}

So it looks like I'm fighting multiple bugs here. First it takes my 3 column HQL query, turns it into a 2 column SQL query, then takes my 2 column ResultSet and turns it into a 1 column Object[].

Has no one ever done this before?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.