BaseORMService – Hibernate Criteria for “property not in”

Just a little note for anyone else interested. To filter properties that are *not* in an array (i.e. don’t select from entity if foo is in bar) this is how its done in hibernate:

  Restrictions.not("id", new long[] {2, 3})

And because ColdBox’s BaseORMService just proxies out to the hibernate Restrictions class, it’s easily accomplished in CB: (Showing as-is for my purposes)

    Restrictions.not('user_id', JavaCast("java.lang.Integer[]", blocked_users ) )

Just be careful to check that your filter is not an empty array, otherwise Hibernate will complain about ‘()’ being bad sql grammar.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

WordPress Appliance - Powered by TurnKey Linux