# @Filter not working with session.load by ID

**URL:** <https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710>\
**Category:** Hibernate ORM\
**Created:** [September 16, 2021, 7:54am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710 "2021-09-16T07:54:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [September 16, 2021, 7:54am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/1 "2021-09-16T07:54:50Z")

</div>

Hello,

I saw that there was no plan to enable @Filter for entity retrieval by ID: [https://hibernate.atlassian.net/browse/HHH-11485](https://hibernate.atlassian.net/browse/HHH-11485)

But unfortunately, our confidentiality mechanisms are based on the data filter.

`WHERE CONFIDENTIALITE=ENTREPRISE_NAME`

Suddenly that would prohibit using session.get () or load () or getId () otherwise we risk recovering data that should not be visible.

It’s still very restrictive …

The solution to still not pass a Query does not satisfy me either: [java - How can I get an Entity by ID whilst applying a Hibernate @Filter? - Stack Overflow](https://stackoverflow.com/questions/58186871/how-can-i-get-an-entity-by-id-whilst-applying-a-hibernate) -filter

Difficult to form an opinion of how to do it, an idea?

Thank you  
Vincent

---

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [September 16, 2021, 8:08am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/2 "2021-09-16T08:08:32Z")

</div>

I saw that the problem did not arise with the `@Where` for the soft-delete, phew! 🙂

---

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [September 16, 2021, 2:17pm UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/3 "2021-09-16T14:17:16Z")

</div>

I saw that there were these 2 limitations to @filter : cache + direct access :

> **[Hibernate's @Filter Annotation - Apply Dynamic Filters at Runtime](https://thorben-janssen.com/hibernate-filter/)**
>
> How to define, configure, and activate parameterized filter criteria that Hibernate applies to all queries.

---

<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:** [September 17, 2021, 6:58am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/4 "2021-09-17T06:58:25Z")

</div>

We fixed this in Hibernate 6.0: [https://hibernate.atlassian.net/browse/HHH-14772](https://hibernate.atlassian.net/browse/HHH-14772)

---

<div class="post-metadata">

**Author:** ![boutss](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/boutss/32/1543_2.png) [@boutss](https://discourse.hibernate.org/u/boutss)\
**Post date:** [September 17, 2021, 8:22am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/5 "2021-09-17T08:22:58Z")

</div>

Ah top!  
Only the find or also the get and load?

---

<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:** [September 20, 2021, 7:47am UTC](https://discourse.hibernate.org/t/filter-not-working-with-session-load-by-id/5710/6 "2021-09-20T07:47:32Z")

</div>

All access methods will now consider the filters properly.
