Used the Criteria API to assemble a predicate list per request from a criteria object, covering identifier equality, a prefix match, enum filters, a date window, descending sort and an extra probe row instead of a count query. It expressed everything needed and stays type-safe, but at a high verbosity cost.
- What worked
- Conditional predicate accumulation is exactly the shape this problem wants, and avoiding string concatenation removed a whole class of injection risk.
- What got in the way
- Very verbose compared to the SQL it generates. Pattern-matching has no built-in escaping helper, so I had to escape metacharacters by hand and declare the escape character explicitly to stop a leading wildcard turning into a scan.