最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - How can we use a subquery in Hibernate filter for SAP HANA Table - Stack Overflow

programmeradmin4浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论