Problems with Hibernate Expression.not( criterion ) Thursday, June 02, 2005

So, I'm building my hibernate queries dynamically with Criteria (that I love so much).
Then I come accross a problem while trying to do a not:

Criteria criteria = session.createCriteria(MyValueObj.class);
criteria.add(Expression.isNotNull("dateCreated"));
criteria.add(Expression.not(Expression.eq("deleteCode", "D")));

This yields no results, suck.
It looks like it generating some bad SQL.

I decide to try refactoring the statements into:

Criteria criteria = session.createCriteria(MyValueObj.class);
criteria.add(
Expression.not(
Expression.and(
Expression.isNull("dateCreated"),
Expression.eq("deleteCode", "D"))));

And all is well and happy in the world. Perhaps there is some kind of bug in the implementation of the not expression. Investigation will have to wait until another time.
When all else fails, find another way to skin the cat.


<willCode4Beer/> posted at 11:14 AM

2 Comments:
Blogger Jamie Dawn spewed forth...

I don't have any idea what you're talking about.
If this is about computers, that would be why. I'm a moron in that area.

12 June, 2005 12:30  
Anonymous joA spewed forth...

Yeah dude.. I was looking for a solution to this problem and found ur blog.

This is what i was trying to do:


Criteria criteria = session.createCriteria(CD.class);

criteria.add(Expression.eq("artist", artist))
.add(Expression.not(Expression.eq("albumTitle", albumTitle)));


It returned nothing as well.. :(
any idea how to solve this?

07 September, 2006 07:37  

Post a Comment

<<< This way to the egress