繁体   English   中英

使用基于地图键的HQL选择值

[英]Selecting value using HQL based on a key of a Map

假设我有以下JPA映射。



    @Entity
    @Table(name = "transaction")
    public class Transaction {

        @ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
        @JoinTable(name = "trx_addi_info")
        private Map additionalInfo;


    }

我想写HQL来获取所有在AdditionalInfo映射中具有特定键值对的交易。 我想我必须像下面这样加入



    SELECT trx FROM Transaction trx inner join trx.additionalInfo addInfo WHERE addInfo.????

但是我不清楚如何在附加信息映射中放置WHERE子句以与特定键值对匹配。 有人可以帮我吗?

提前致谢。

您需要使用特定于HQL index()函数,该函数适用于联接的索引集合(数组,列表和映射)的别名。 请参阅第14.10 Hibernate参考文档的表达式

//Example of HQL returning `Transaction` object that have `additianlInfo` with   
//the `KEY` equal to the string `test`

SELECT trx FROM Transaction trx inner join trx.additionalInfo addInfo WHERE index(addInfo) > 'test' 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM