-
Notifications
You must be signed in to change notification settings - Fork 1.5k
FilterDef and Filter annotations not working after upgrade. #2565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers. If you can also provide a demonstration that whatever you try to do works with plain JPA we'd appreciate it. |
Filters Working Code Base : https://github.com/achris001c/MultiTenantService/tree/working Code Base where Filters don't work : https://github.com/achris001c/MultiTenantService/tree/not-working Dependencies on "working" branch: Spring boot v2.1.2, Spring data JPA v2.1.4 , Hibernate 5.3.7.Final |
@achris001c -- Was this ever fixed? Are FilterDefs no longer supported? |
@schauder -- The reporter of this issue closed their own issue after 2 days, and this loss of functionality was never addressed by the project. Closing this issue appears to have been a mistake. Their "minimally reproducible example" shows this not working all the way up to 2.7. Someone else has gone out of their way to restore this functionality for themselves: https://babystepstopro.medium.com/adding-hibernate-entity-level-filtering-feature-to-spring-data-jpa-repository-76bf8ddd42ff Somewhere between Spring Boot 2.1 and 2.5, Spring stopped creating JpaRepository queries through EntityManager? Can this functionality be brought back in Spring Boot 3.x? We can unwrap our own Sessions and enable our own filters in our own Service layers. Spring Boot has a hard dependency on Hibernate, so why not restore this feature? |
I'm reopening this so someone can take a look what is going on.
All queries executed by Spring Data JPA go through the |
I'm using the latest spring data jpa, and still met the same issue. As my experience, the transaction must be enabled so that the filter could be applied. I don't know if it is the behavior from spring data jpa or hibernate. In hibernate document it uses the code below to enable filter entityManager
.unwrap(Session.class)
.enableFilter("activeAccount") //This line enables the filter
.setParameter("active", true);
List<Account> accounts = entityManager.createQuery(
"select a from Account a", Account.class)
.getResultList();
assertEquals(2, accounts.size()); But I don't see any related code to use transaction. I'm not the expert so could anyone determine the behavior if filter usage must comes with transaction is determined by hibernate or spring data jpa? |
I'm using Hibernate 6.5.5 and had to add the @FilterDef(name = "FILTER_NAME", autoEnabled = true) I didn't find any related instruction in the Hibernate migration guides. |
Previous Dependency Versions:
Upgraded Dependency Versions:
Query Generation with earlier version (Repository.getById()):
Hibernate: select useraccoun0_.id as id1_2_, useraccoun0_.tenant_id as tenant_i4_2_, useraccoun0_.first_name as first_na2_2_, useraccoun0_.last_name as last_nam3_2_ from user_account useraccoun0_ where useraccoun0_.tenant_id = ? and useraccoun0_.id=?
Query Generation after upgrade (Repository.getById()):
Hibernate: select useraccoun0_.id as id1_2_0_, useraccoun0_.tenant_id as tenant_i4_2_0_, useraccoun0_.first_name as first_na2_2_0_, useraccoun0_.last_name as last_nam3_2_0_ from user_account useraccoun0_ where useraccoun0_.id=?
The text was updated successfully, but these errors were encountered: