-->
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.  [ 2 posts ] 
Author Message
 Post subject: [newbie] HQL : how to manage null parameters?
PostPosted: Wed Feb 02, 2005 10:07 am 
Newbie

Joined: Thu Sep 30, 2004 6:00 am
Posts: 13
Hello,

I have a simple HQL query like : " From Table WHERE Prop = :x "

It works in most cases but I have a problem when x is "null".

When x is null I'm expecting that Hibernate translates this HQL query into a SQL query like " select * from table where prop is null "

But the "getNamedQuery" method needs a Hashtable to define the parameters. And I cannot put a null value in a Hashtable.

If I don't define the x parameter at all in the getNamedQuery, it throws an error.


I did a quick fix. I've created two HQL queries. One with " Prop = :x " and the other with the literal : " Prop is null ".
If x is not null I call the first HQL query. Else the second one.

But I really don't like that so if anybody knows another way to fix it, it'd be great!

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 13, 2005 3:09 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
I have the same problem - also I can't find a way to:
a) add a 'Criteria' to a 'Query'
b) form my own select stmt with 'Criteria'

eg. if(x == 'a')

select max(t.num) from table t where t.name = x

eg. if(x == null)

select max(t.num) from table t where t.name is null

does anyone know a solution...please?


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