# Compile-time HQL query validation

**URL:** <https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742>\
**Category:** Hibernate ORM\
**Created:** [October 12, 2022, 2:53pm UTC](https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742 "2022-10-12T14:53:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mconner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mconner/32/1998_2.png) [@mconner](https://discourse.hibernate.org/u/mconner)\
**Post date:** [October 12, 2022, 2:53pm UTC](https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742/1 "2022-10-12T14:53:52Z")

</div>

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](https://github.com/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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 13, 2022, 3:31pm UTC](https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742/2 "2022-10-13T15:31:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mconner](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mconner/32/1998_2.png) [@mconner](https://discourse.hibernate.org/u/mconner)\
**Post date:** [October 14, 2022, 5:11pm UTC](https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742/3 "2022-10-14T17:11:31Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [October 17, 2022, 9:45am UTC](https://discourse.hibernate.org/t/compile-time-hql-query-validation/6742/4 "2022-10-17T09:45:01Z")

</div>

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