I am implementing Instance based authorisation. And for that, I need to add entityfilter to my JPA model:
@Filter(name = "entityFilter", condition = "\"TablePrimaryKey\" in (:values)")
I can provide values to values at runtime using another select from the same table:
SELECT t.TablePrimaryKey FROM \"com.abc.xyz::NameSpace.Table\" t "
+ " WHERE (t.purchasingParty IN (:party_id)
But the values could grow to thousands of guids, which brings down the query performance.
So, in the original entity filter, I want to use a subquery as below:
@Filter(
name = "entityFilter",
condition = "EXISTS ("
+ " SELECT 1 FROM \"com.abc.xyz::NameSpace.Table\" d "
+ " WHERE d.TablePrimaryKey IN ("
+ " SELECT t.TablePrimaryKey FROM \"com.abc.xyz::NameSpace.Table\" t "
+ " WHERE (t.purchasingParty IN (:party_id))"
+ " )"
+ ")"
But this takes :NameSpace as a filter parameter and the SQL generation fails.
How can a subquery in the Hibernate @Filter be effectively used? Do you have any other suggestions on how to handle such use cases?