HQL query select one set of columns vs select other columns when a particular column is null

Right, a fully working solution, that would take into account the fact that myId can be null, would be:

@Query("SELECT item FROM Item WHERE a = ?1 AND b=?2 AND c=?3 AND (?4 IS NULL OR (myId IS NOT NULL AND myId = ?4))")

Quite a mouthful, even if there might be utility functions that allow a more concise expression of the same condition.

I agree, it’s too complex for its own good. Using the Criteria API or QueryDSL would definitely be a better solution. But then we can’t force anyone to use it :slight_smile: