Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于映射键使用HQL选择值_Java_Hibernate_Hibernate Mapping - Fatal编程技术网

Java 基于映射键使用HQL选择值

Java 基于映射键使用HQL选择值,java,hibernate,hibernate-mapping,Java,Hibernate,Hibernate Mapping,假设我有以下JPA映射 @Entity @Table(name = "transaction") public class Transaction { @ElementCollection(targetClass = String.class, fetch = FetchType.EAGER) @JoinTable(name = "trx_addi_info") private Map additionalInfo;

假设我有以下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.????

但我不清楚如何在additionalInfo映射中放置WHERE子句以与特定的键值对匹配。有人能帮我吗


提前感谢。

您需要使用HQL
index()
特定函数,该函数适用于已加入索引的集合(数组、列表和映射)的别名。请参阅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'