[hibernate-dev] Hibernate Disjunction Criteria broken: returns true for empty list of criteria
Darryl Miles
darryl-mailinglists at netbauds.net
Sat Nov 1 07:03:49 EDT 2008
William Pugh wrote:
> When you form a Hibernate Disjunction criteria, but don't add any
> clauses to it, you get a criteria that matches everything.
Here is my crack at it:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3583
I still maintain that adding empty Disjunction() in Critera API
expression is a programming error. Empty Conjunction() only work by
chance and this is because of the implicit enclosing Conjunction() due
to the use of the add() method in the API like:
critera.add(Expression.someexpr()).add(Expression.someexpr());
To prove this point (that historically it's a programming error) try
using a mixture of empty Conjuction() (or empty Disjunction())
expressions inside other each other and see how soon you become unstuck.
resultList = s.createCriteria(Student.class)
.add( Restrictions.disjunction()
.add( Property.forName("studentNumber").gt( new Long(666) ) )
.add( Property.forName("studentNumber").lt( new Long(102) ) )
.add( Restrictions.disjunction()
.add( Restrictions.disjunction() )
.add( Restrictions.conjunction()
.add( Restrictions.conjunction() )
.add( Restrictions.conjunction() )
)
)
)
.addOrder( Order.asc( "studentNumber" ) )
.list();
Hopefully the patch produces a good/better API.
Darryl
More information about the hibernate-dev
mailing list