-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Filters: how to filter by empty parameter list?
PostPosted: Wed Apr 22, 2015 3:21 pm 
Newbie

Joined: Wed Apr 22, 2015 1:58 pm
Posts: 1
I'm using JPA + Hibernate with Postgres.

I have a whole bunch of Hibernate Filters with the following condition: field IN (:values).

When values is an empty collection, Postgres chokes on the generated SQL: field IN ().

The intended behaviour is that if values is empty, the condition should evaluate to false.

Anyone have any idea how to achieve that intended behaviour?

I've tried the following alternatives, but none work.

A1. field = ANY(bigint[:values]): Hibernate incorrectly prefixes the table alias onto "bigint[]", resulting in bogus SQL: field = ANY(table0_.bigint[]).
A2. Passing in a collection with a single null entry, in an attempt to yield the query: field IN (null). Hibernate throws an NPE when trying to get the type of the null entry.

There are two solutions that would work, but both suck for other reasons:

S1. Enable a false-filter instead of the real filter whenever the collection is empty. This would double the number of @FilterDefs and @Filter annotations required, which would be awful.
S2. Pass a collection with a single invalid value, e.g. 2^63 - 1 for a bigint field, or some highly random bogus string for text fields. Obviously this is sucky solution, but it would work, and it limits the suck-i-tude more than S1.

Help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.