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