# Compile time check in Blaze-Persistence?

**URL:** <https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987>\
**Category:** Hibernate ORM\
**Created:** [November 24, 2025, 8:25am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987 "2025-11-24T08:25:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marko1212](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/marko1212/32/4163_2.png) [@Marko1212](https://discourse.hibernate.org/u/Marko1212)\
**Post date:** [November 24, 2025, 8:25am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/1 "2025-11-24T08:25:17Z")

</div>

Hi!

In Blaze Persistence is it possible to have compile-time check ?

```auto
CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)
    .from(Cat.class)
    .select("cat.age");

```

In this query, if by mistake I write `“cat.aged”` (`age` is a property of `Cat`), there won’t be any compile time exception, right ?

I understand from the documentation that compile time check is possible if using Entity Views module, is it correct?

And without Entity Views, with just the basic setup and packages ?

Thanks in advance!

---

<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:** [November 24, 2025, 9:22am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/2 "2025-11-24T09:22:52Z")

</div>

Some people use the constants that the Hibernate JPA metamodel generator produces for some type-safety i.e.

```
CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)
  .from(Cat.class)
  .select(Cat_.AGE);

```

But that will obviously not check at compile time if the `age` attribute is assignable to `Integer`. The checks for entity views are at application boot time, though they are more thorough, i.e. assignability is checked.

You can also write queries with the JPA Criteria API or QueryDSL if you would like to exchange a little readability for type-safety.

---

<div class="post-metadata">

**Author:** ![Marko1212](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/marko1212/32/4163_2.png) [@Marko1212](https://discourse.hibernate.org/u/Marko1212)\
**Post date:** [November 24, 2025, 9:59am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/3 "2025-11-24T09:59:49Z")

</div>

Thanks a lot! Is the (partial) compile time check with Hibernate JPA metamodel generator also working with implicit or explicit `JOIN` statements, subqueries etc.? I.e. can a BP query always be rewritten so that there is this kind of check at compile time.

Here is an example with explicit `JOIN` :

```auto
CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)
    .from(Cat.class)
    .select("kittens.age")
    .where("kitty.age").gt(1)
    .innerJoin("kittens", "kitty");

```

---

<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:** [November 24, 2025, 10:36am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/4 "2025-11-24T10:36:30Z")

</div>

Since Hibernate ORM and JPA don’t support implicit joins over collections, that’s not going to work unfortunately. You would have to reformulate your query to use explicit joins then.

---

<div class="post-metadata">

**Author:** ![Marko1212](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/marko1212/32/4163_2.png) [@Marko1212](https://discourse.hibernate.org/u/Marko1212)\
**Post date:** [November 24, 2025, 4:20pm UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/5 "2025-11-24T16:20:32Z")

</div>

Just to make sure I have understood you correctly, the query :

`CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)`  
` .from(Cat.class)`  
` .select("kittens.age")`  
` .where("kitty.age").gt(1)`  
` .innerJoin("kittens", "kitty");`

will not work, as it is written ? I took it from here:

> **[Blaze Persistence - Criteria API for JPA backends](https://persistence.blazebit.com/documentation/1.6/core/manual/en_US/)**

3.1.2 paragraph

---

<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:** [November 25, 2025, 8:07am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/6 "2025-11-25T08:07:40Z")

</div>

> [@Marko1212](#):
>
> Just to make sure I have understood you correctly, the query :
> 
> `CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)`  
> ` .from(Cat.class)`  
> ` .select("kittens.age")`  
> ` .where("kitty.age").gt(1)`  
> ` .innerJoin("kittens", "kitty");`
> 
> will not work, as it is written ?

This example will work as it is, but you asked about whether this BP query could be rewritten to JPA Criteria to achieve compile time checks:

> [@Marko1212](#):
>
> Thanks a lot! Is the (partial) compile time check with Hibernate JPA metamodel generator also working with implicit or explicit `JOIN` statements, subqueries etc.? I.e. can a BP query always be rewritten so that there is this kind of check at compile time.

And the answer is yes, but you would need to use an explicit join in the select clause i.e. instead of `kittens.age` you will have to refer to `kitty.age` directly, because JPA Criteria and Hibernate ORM don’t support implicit joins over collections.

For the sake of example, this could be written as:

```java
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Integer> query = cb.createQuery(Integer.class);
Root<Cat> cat = query.from(Cat.class);
SetJoin<Cat, Cat> kitty = cat.join(Cat_.kittens);
query.where(cb.greaterThan(kitty.get(Cat_.age), 1));
query.select(kitty.get(Cat_.age));

```

---

<div class="post-metadata">

**Author:** ![Marko1212](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/marko1212/32/4163_2.png) [@Marko1212](https://discourse.hibernate.org/u/Marko1212)\
**Post date:** [November 25, 2025, 8:28am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/7 "2025-11-25T08:28:38Z")

</div>

Ok, thanks a lot, I have understood now.

Actually, I have not formulated my question well :

the question was : can i rewrite **in Blaze-Persistence** the query with JOINs (and yes, the query is already written in Blaze Persistence) **but** _with compile time checks_, so using the Hibernate JPA metamodel. So rewrite the same query, in Blaze-Persistence, but with compile-time checks (that remain partial, as I understood from your first reply).

And the fact BP supports implicit JOIN over collections is good news.

---

<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:** [November 25, 2025, 9:19am UTC](https://discourse.hibernate.org/t/compile-time-check-in-blaze-persistence/11987/8 "2025-11-25T09:19:14Z")

</div>

I guess you could write something like this:

```auto
CriteriaBuilder<Integer> cb = cbf.create(em, Integer.class)
    .from(Cat.class)
    .select("kitty." + Cat_.AGE)
    .where("kitty." + Cat_.AGE).gt(1)
    .innerJoin(Cat_.KITTENS, "kitty");

```

But note that you don’t have to fully give up on type safety. Blaze-Persistence has a QueryDSL frontend as well as a JPA Criteria API frontend as well, which both produce the Blaze-Persistence `CriteriaBuilder` in the end. So you can still combine that with entity views or write most of your query with one API and switch to the Blaze-Persistence `CriteriaBuilder` API when needed.
