[hibernate-issues] [Hibernate-JIRA] Updated: (HHH-3583) Crietia API with empty Disjunction expressions doesn't work in a natural way

Darryl Miles (JIRA) noreply at atlassian.com
Mon Nov 3 14:32:04 EST 2008


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3583?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Darryl Miles updated HHH-3583:
------------------------------

    Attachment: hib-with-EmptyMode-version2.diff

Updated patch.  This replaces and obsoletes the previous one.

Corrects minor error to changes in toSqlString() where an "else" case should have been used on the bottom when checking EmptyMode settings.

This update also improves javadoc wording.

> Crietia API with empty Disjunction expressions doesn't work in a natural way
> ----------------------------------------------------------------------------
>
>                 Key: HHH-3583
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3583
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: query-criteria
>    Affects Versions: 3.3.1
>            Reporter: Darryl Miles
>            Priority: Minor
>         Attachments: hib-with-EmptyMode-version2.diff, hib-with-EmptyMode.diff
>
>
> An empty Disjunction() expression in a Criteria API query results in a statement of: SELECT foo FROM table WHERE (foo.someColumn='someValue') OR (1=1)
> The reason for the "1=1" is due to the implict Conjunction() which is the default for criteria.add(Expression.something()).add(Expression.something())
> Thinking through this problem domain until conclusion you end up at the question "How should an empty Junction be handled (in respect of its enclosing expression) ?"  This is akin to SQL NULL type handling, i.e. NULL value is not a value; an "empty expression" is not an expression.
> Looking a the problem from the point of view what mades the most natural and straight forward Critiera API the natural expectation is for an empty expression to have no observable effect on the result set.  This depends on the nature of the enclosing Junction the expression belongs to (is it Conjunction() or Disjunction() ?).
> The next issue you have to deal with is what if you have nested empty expressions, the natural way a user expects it to work is to resolve an Junction graph of empty expressions to a single empty expression, for example "((() OR ()) AND () AND (() OR ()))" is equivalent to "()".  The notation "()" refers to an empty expression.  So then it is necessary to deal with recursion.
> In some situations it maybe necessary/desired to dictate what to do with an empty expression, for example wanting to always treat the result as a logical TRUE, or logical FALSE in your expression graph on a Junction() by Junction() basis.
> Please find attached a patch with 2 new testcases that will resolve the unnatural behavior observed when an empty Disjunction() is used in a Criteria API expression.  The testcases cover testing a number of nesting scenarios.
> Should this patch be reviewed and approved the only external change from the previous version should be when an empty Disjunction() added into the expression of a Critiera API query it should return less data than before, since the "OR (1=1)" expression will become "OR (1=0)".  Due to the previous behavior the additions I now make in creating EmptyMode at the same time are just not visible.
> Please also advise if any additional documentation is needed citing references to the section/files/javadoc where I can document this feature/change best.

-- 
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