Open MartynenkoA opened 6 years ago
in console i have this request select user0_.user_id as user_id1_00, user0_.first_name as first_na2_00, user0_.last_name as last_nam3_00, user0_.tenant_id as tenant_i4_00, user0_.username as username5_00 from userinfo user0 where user0_.user_id=?
where is "user0_.tenant_id = ?" ??
Same problem here. Did you manage to find a solution for this?!
It looks like hibernate filter does not work on findById ! https://coderanch.com/t/543756/databases/Hibernate-Filter-working
According to https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html (see "Example 89. Query entities mapped with @Filter"): "Filters apply to entity queries, but not to direct fetching. Therefore, in the following example, the filter is not taken into consideration when fetching an entity from the Persistence Context."
To resolve the issue you may use custom query in your JpaRepository like this:
@Query("SELECT u FROM User u WHERE u.id = ?1")
Optional
In this case Hibernate adds condition from @Filter to the query.
As @MikhailEpatko mentioned, this is indeed not applied due to direct fetching. This can also be fixed by overriding the SimpleJpaRepository base class.
A production ready example can be found here: https://github.com/M-Devloo/Spring-boot-auth0-discriminator-multitenancy/pull/3/files
Note: this is a part of my SaaS Multi Tenancy implementation which is fully tested as well has been proven to be reliable in production.
findById is not working, when i tring to getbyid (in header tenant1) but userId is id of user tanant2 in responce i get information about user2