As mentioned in a different answer to the question referenced previously, the following HQL construct works for me:
select o from Product o WHERE :value is null or o.category = :value
if :value
is passed in as null
, all Products are returned.
See also Optional or Null Parameters
Note that this won't work in some versions of Sybase due to this bug, so the following is an alternative:
select o from Product o WHERE isnull(:value, 1) = 1 or o.category = :value
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…