-->
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.  [ 7 posts ] 
Author Message
 Post subject: set NULL with Query.setParameter
PostPosted: Sun Aug 06, 2006 5:36 am 
Newbie

Joined: Sun Aug 06, 2006 4:12 am
Posts: 4
Hi all,

is there a way to set NULL with Query.setParameter in Hibernate 3.1.3?

Code:
System.out.println(
      createQuery("from Table t where w.field = null")
      .list()
      .size()
);


>> Returns 2 rows

Code:
System.out.println(
      createQuery("from Table t where t.field = :param")
      .setParameter("param", null)
      .list()
      .size()
);


>> Returns 0 rows

Maybe there is an constant to use?

Best regards,
Jens


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 12:50 pm 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
Jens,

You've probably already thought of this, but just in case...

Here's a kludge that will keep you operating until a better answer comes:

Code:
if(obj == null) {
  qry = createQuery("from Table t where w.field = null");
}else{
  qry = createQuery("from Table t where t.field = :param");
  qry.setParameter("param", obj);
}

int size = qry.list().size();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 12:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
guys ;)

"field = null" is always false in sql and hql which both uses the same ternary logic.

you should check for null by "field is null".

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 3:29 pm 
Newbie

Joined: Sun Aug 06, 2006 4:12 am
Posts: 4
max wrote:
guys ;)

"field = null" is always false in sql and hql which both uses the same ternary logic.

you should check for null by "field is null".


Are you shure?

Code:
createQuery("from Table t where t.field = null")

and
Code:
createQuery("from Table t where t.field is null")


return the same result...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 3:32 pm 
Newbie

Joined: Sun Aug 06, 2006 4:12 am
Posts: 4
kheston,

that's the way I go up to now...
But it's a good idea. ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 4:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i'm sure that in SQL x = null does not evalute to what you think it does.

look it up if you don't belive me.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 06, 2006 4:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
btw. just to be correct, x = null actually doesn't evaluate to either true or false...anyway look up sql, null and ternary logic.

_________________
Max
Don't forget to rate


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