# Out of Memory Error while Parsing JPQL Query

**URL:** <https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420>\
**Category:** Hibernate ORM\
**Created:** [April 24, 2024, 11:55am UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420 "2024-04-24T11:55:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonasu](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jonasu](https://discourse.hibernate.org/u/jonasu)\
**Post date:** [April 24, 2024, 11:55am UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420/1 "2024-04-24T11:55:06Z")

</div>

We noticed a potential memory leak while parsing JPQL queries in 6.4.4 . In 6.2.22 everything works fine We filed a bug report here: [HHH-17998](https://hibernate.atlassian.net/browse/HHH-17998) In our application we doubled the heap size and still occasionally run into OOMs. Are there any similar experiences with increased memory usage while parsing queries?

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [April 24, 2024, 2:55pm UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420/2 "2024-04-24T14:55:37Z")

</div>

I’m pretty sure we did not receive other reports of significantly increased memory usage, at least from version 6.2 to 6.4. The query you’re trying is huge, especially for HQL, so my immediate suggestion would be to find possible inefficiencies and try to optimize there or even think about splitting some of it up.

Since you opened an issue on our tracker and provided a reproducer someone might be able to look into it to find possible issues regarding memory usage, but Hibernate is an open source project and I cannot guarantee a fast response. The best course of action is trying to contribute yourself, you could start analyzing this through async-profile or JMC or at least provide us data (e.g. heap dumps when OOM occurs) that can help us get a general idea of what might be going on.

---

<div class="post-metadata">

**Author:** ![Anonimo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/anonimo/32/3168_2.png) [@Anonimo](https://discourse.hibernate.org/u/Anonimo)\
**Post date:** [April 28, 2024, 2:44pm UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420/3 "2024-04-28T14:44:15Z")

</div>

I have an OutOfMemoryError too because of Hibernate I think.

The problem occurs one minute after starting the program execution. From the moment the program is executed, the memory usage increases progressively until it reaches a point where the error occurs. This is strange because until a few days ago, when I ran it for the last time, it didn’t happen.

Here is my StackOverflow question:  
[spring boot - JPA error: OutOfMemoryError - Stack Overflow en español](https://es.stackoverflow.com/questions/619093/jpa-error-outofmemoryerror?noredirect=1#comment1089284_619093)

---

<div class="post-metadata">

**Author:** ![marcio.koch](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/marcio.koch/32/3866_2.png) [@marcio.koch](https://discourse.hibernate.org/u/marcio.koch)\
**Post date:** [February 25, 2025, 1:14pm UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420/4 "2025-02-25T13:14:58Z")

</div>

Same error in 6.6.5.

```auto
org.hibernate.orm.query.hql : HQL : select empresaEntity
from EmpresaEntity empresaEntity
where empresaEntity.ativo = ?1 and (lower(FUNCTION('unaccent', empresaEntity.nome)) like lower(concat(concat(?2,FUNCTION('unaccent', ?3)),?4)) escape '!' or lower(FUNCTION('unaccent', empresaEntity.razaoSocial)) like lower(concat(concat(?5,FUNCTION('unaccent', ?6)),?7)) escape '!' or lower(FUNCTION('unaccent', empresaEntity.cnpj)) like lower(concat(concat(?8,FUNCTION('unaccent', ?9)),?10)) escape '!' or lower(FUNCTION('unaccent', FUNCTION('regexp_replace', empresaEntity.cnpj, ?11, ?12, ?13))) like lower(concat(concat(?14,FUNCTION('unaccent', ?15)),?16)) escape '!')
order by empresaEntity.id asc
java.lang.OutOfMemoryError: Java heap space

```

---

<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:** [February 26, 2025, 10:25am UTC](https://discourse.hibernate.org/t/out-of-memory-error-while-parsing-jpql-query/9420/5 "2025-02-26T10:25:11Z")

</div>

If it’s so easy to reproduce, please create a reproducer with our [test case template](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) and create a bug ticket in our [issue tracker](https://hibernate.atlassian.net) and attach that reproducer.

Once we have a reproducer, we will work on this as soon as possible.
