Compile-time HQL query validation

I’ve got a number of classes performing queries using HQL. We are using IntelliJ, which has a Language Injection feature which can validate the HQL, showing errors and provide code-completion. I’m looking for a command-line equivalent that to be integrated into a gradle build. It would generate errors if the HQL (or JPQL) could not be validated against our entities. Is there some way to do this?

I found hibernate/query-validator, but it appears there’s been no activity on that for some time, is only in SNAPSHOT (per the readme), and doesn’t appear in searches on either search maven org, or mvnrepository com, so I’m assuming it is essentially a dead project.

It was a PoC project, but you have to understand that validating queries is hard since there is a lot of context that must be considered. The best way to validate your queries is to register them all as named queries, which are checked automatically since these are compiled/translated in the Hibernate boot phase.

@beikov , While I think we could definitely benefit from moving more of our queries to named queries, there are some queries that are relatively simple, but there’s some assembly required. That is, part of the query is included only if a parameter is included. (The IntelliJ plugin is actually still able to make sense of it, mostly). We could create a query for each permutation, but that quickly gets cumbersome. And we could look at moving some of these to CriteriaBuilder. I was just hoping there was already a mechanism for this.

Thanks for your quick response.

As soon as you get to dynamic queries, there is no way other than using CriteriaBuilder if you want type safety.