-->
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: Why still require "is null" in ejb3 queries?
PostPosted: Tue Apr 24, 2007 6:38 pm 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
I know that this is probably a topic that has been hashed and rehashed, but searching these forums doesn't seem to turn anything up about "is null".

I'm wondering why queries still need to use "is null" instead of allowing null comparison with "=" which is converted behind the scenes into an "is null" query that's sent to the actual db.

If I do:
Code:
  select * from com.ign.Foo where name=null

or if I do the following with :name bound to null:
Code:
  select * from com.ign.Foo where name=:name

then why can't that be translated in the background to be
Code:
  select * from FooTable where name is null


I understand tri-state logic and the reasons for having it in databases (specifically so that table joins work the way they do). I don't understand why we have to maintain that separation in the syntax of the query language. It just creates hassle and I have never understood what we gain by this.

As a result of these problems, I have in the past used a specific value to indicate null rather than using null itself so that I do not need to create one version of the query for each combination of is null. That's a completely ridiculous thing to have to do.

In other situations I've build the query with a ternary operator for each nullable field like
Code:
  String query = "select * from FooTable where name"+ (name==null?" is null":("="+name))


Is there a reason for continuing to require "is null"? It just seems like madness to me.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I though about that one night with Gavin, and yes there is a reason to keep HQL as a ternary-logic based query language. There were some queries you could not achieve otherwise.

I can't remember what it was but by thinking hard, one can reach the same conclusion.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: what queries?
PostPosted: Wed Apr 25, 2007 8:57 pm 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
What sort of queries can't you do? I've asked others this question before and no one has ever actually given me an example of a query that requires it.

Considering that:
....ANYTHING = null
resolves to false for all values of ANYTHING, what possible queries could use that? If you need an always false condition then you can just do "1=0" or some other always false condition.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 9:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it does not resolve to false, it resolves to null, that's a fundamental difference. It mean the negation of anything = null is also null, not true.
As I said, I can't remember the reasoning, hence the queries, but by digging around what I said you should find the family of queries you can't reach.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 4:31 am 
Beginner
Beginner

Joined: Fri Dec 17, 2004 8:30 pm
Posts: 20
Ok, so if there are queries where it's useful then why not flip things around? Why not have "=null" behave like "is null" and "is null" behave like "=null"? If you wanted to avoid confusing people, you could have used "is unknown" or some other keyword.

That way, the infinitesimal corner cases where this sort of thing is needed would be covered while the far more common cases would not require the torturous query jimjamming that I described above.

I know that nothing is going to change now. I love hibernate and have used it for years (and am now starting to use ejb3). It just seems so sad that this one problem wasn't dealt with when you had the chance to change things.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The amount of Java developers is much smaller than the amount of SQL developers.

_________________
Emmanuel


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.