Heres a query to illustrate some (psuedo) dynamic HQL
SELECT car FROM Car car WHERE (:showRedCars = false OR car.color = 'red') OR (:showBlackCars = false OR car.color = 'black') OR (:showOrangeCars = false OR car.color = 'orange')In the query above :showRedCars, :showBlackCars and :showOrangeCars are standard HQL parameters, these act us gaurds to the actual where statements. If showRedCars is set to true then car.color = 'red' will be applied. If :showRedCars is set to false then the statement is skipped.
You are not limited to jusr true/false values for example
OR (:regYear <> 2001 OR car.color ='silver')
In the above query if regYear is set to 2001 then the will return cars with silver color.