# Hibernate 6.3.1 issue with query cache

**URL:** <https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545>\
**Category:** Hibernate ORM\
**Created:** [November 14, 2023, 2:56pm UTC](https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545 "2023-11-14T14:56:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amir](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/amir/32/2415_2.png) [@amir](https://discourse.hibernate.org/u/amir)\
**Post date:** [November 14, 2023, 2:56pm UTC](https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545/1 "2023-11-14T14:56:11Z")

</div>

I believe there is a bug with cache integration.

Let’s see on the following test case:

Turn on caching and use ehcache provider

Let’s persist some entity with 2 fields, bool & string

Now let’s do hql select a from EntityA where a.name like ‘xxx’ and give hints to cache this query

results returned as expected. Now 2nd level cache has entry in query-cache, also entity is in 1st level cache entity manager persistence context

now lets do one more hql select a from EntityA where a.someBoolFlag=false

results returned as expected - the same entity as from the first query is returned and all fields of this entity is populated. Now 2nd lvl cache has another entry in the query-cache, !!BUT!! that entry has only id populated.

Now, clear entity manager and do the same query(the 2nd one) again. Results returned are strange: entity is returned but only id is populated. So seems it hits the 2nd level cache but because entity there is “broken“ it simply returns that empty entity.

Seems the issue is that when we do 2nd query, we have entity in the session cache. And so logic only populates a primary key and the rest of fields are not initialized/populated from result set and so when it “finishes up“ and pushes result to 2nd lvl cache it has only if populated.

Guess the step where it identifies that entity is in the session cache should be enhanced with disassembling that entity and emulate the process like it is done when it goes the very first time without any cache data present

Hibernate issue with PR to reproduce  
[https://hibernate.atlassian.net/browse/HHH-17423](https://hibernate.atlassian.net/browse/HHH-17423)

---

<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 14, 2023, 3:27pm UTC](https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545/2 "2023-11-14T15:27:26Z")

</div>

Thanks for the report. The Hibernate ORM team will look into it as soon as possible.

---

<div class="post-metadata">

**Author:** ![Benjamin\_Lefevre](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/benjamin_lefevre/32/2828_2.png) [@Benjamin\_Lefevre](https://discourse.hibernate.org/u/Benjamin_Lefevre)\
**Post date:** [November 27, 2023, 4:02pm UTC](https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545/3 "2023-11-27T16:02:18Z")

</div>

have the same issue since I migrated to spring boot 3.2.0. Do you think a fix will be delivered as soon as possible ? thank you

---

<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 27, 2023, 6:05pm UTC](https://discourse.hibernate.org/t/hibernate-6-3-1-issue-with-query-cache/8545/4 "2023-11-27T18:05:21Z")

</div>

If you follow the URLs you will see that this was fixed in Hibernate ORM 6.3.2. So if you want that fix, then update to that version.
