EJB-QL: LIKE operator and NULL fields
843830Jul 13 2004 — edited Jul 30 2004Hi.
Is it the case that [ myField LIKE '%' ] will not return beans whose myField is null?
Is there an easy workaround for this?
My problem is that I'm implementing search functionality, and on our search page some of the parameters may be left blank by the user.
Up till now, I've been using EJB-QL queries for these search pages like:
SELECT OBJECT (o) FROM MyBean o WHERE o.field1 LIKE ?1 and o.field2 LIKE ?2
However, I just now ran into a situation where one of the fields was nullable in the database, and realized that the LIKE '%' clause won't return beans whose field is null.
So in order to handle nulls for a search page with N fields, I'd have to write 2^N EJQ-QL queries, where for each field I'd have a version in which that field was present with the LIKE operator and another version in which that field wasn't present at all (in order to handle cases in which the user left the field empty).
Of course I'm not about to write 2^N queries.
Anyone have any workarounds short of abandoning EJB-QL and using JDBC for the searches, which I'm about to do (since JDBC allows you to build your queries dynamically at run-time)?
Thanks in advance,
-xdarque