【问题标题】:JPA Specification with an Expression带有表达式的 JPA 规范
【发布时间】:2020-07-01 20:22:13
【问题描述】:

我有一个使用此语法构建的 JPA 规范

newSpec = (root, query, cb) -> {        
    return cb.equal(root.get("livelloApprovazione"), root.join( "utentiInteressati").get("livello"));
};

正确映射到我所关注的本机 SQL:

select .... 
from documento documento0_ 
inner join documento_utenti utentiinte1_ 
    on documento0_.id_documento=utentiinte1_.id_documento 
where documento0_.livello_approvazione=utentiinte1_.livello 

我需要在条件的左侧添加一个+1表达式

select .... 
    ....
where documento0_.livello_approvazione + 1 = utentiinte1_.livello 

在条件的一侧加上额外的表达式 + 1。

是否可以实现 JPA 规范谓词这样的 where 条件?如果有怎么办?

【问题讨论】:

    标签: spring jpa


    【解决方案1】:

    试试这个

        newSpec = (root, query, cb) -> 
                cb.equal(
                        cb.sum(root.get("livelloApprovazione"), 1), 
                        root.join( "utentiInteressati").get("livello")
                );
    

    【讨论】:

    • 感谢您的回答 wotks
    • 可能对您探索有用。我在 Intellij 中检查 cb.equal 的签名。它以 2 个表达式作为参数。然后我检查了Expression接口的实现,其中之一是BinaryArithmeticExpression
    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 2019-02-16
    • 2023-02-19
    • 2017-08-19
    • 2020-05-20
    • 1970-01-01
    • 2013-08-16
    • 2021-11-09
    相关资源
    最近更新 更多