[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6065) Have `Restrictions.in()` throw an exception when given an empty collection

JK (JIRA) noreply at atlassian.com
Tue Mar 29 11:44:08 EDT 2011


Have `Restrictions.in()` throw an exception when given an empty collection
--------------------------------------------------------------------------

                 Key: HHH-6065
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6065
             Project: Hibernate Core
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.6.1
            Reporter: JK
            Priority: Minor


I often witnessed SQL errors due to empty collections being passed to `Restrictions.in()`. I strongly suggest to have it throw an `IllegalArgumentException` when given an empty collection to catch what I see as a programming error as early as possible (in the realm of Hibernate). I don't pass arrays to the method overload, but that argumentation and approach might apply to it as well.

Interlude: I assume that `WHERE someColumn IN ()` is illegal in all SQL dialects, though that's just an assumption of mine.

Also, I want to address a possible alternative suggestion upfront: Replacing above illegal SQL with something legal (e.g. `1 = 2`, thus evaluating to false) might hide application errors and cause a lot of headache.

IMHO, the way to go is to throw an exception. If a developer wants to drop the `IN` clause from the query/have it evaluate to false if the collection is empty, that should be done explicitly by adding the criteria restriction inside an `if` clause.

P.S.: This might apply to both `null` being passed as well as Hibernate's non-criteria APIs.

What's your opinion? And did I miss something?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list