假设我有以下 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 子句以匹配 additionalInfo 映射中的特定键值对。有人可以帮我解决这个问题吗?
提前致谢。
最佳答案
您需要使用 HQL index()
特定函数,该函数适用于连接索引集合(数组、列表和映射)的别名。参见 14.10. Expressions 部分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'
关于java - 使用基于映射键的 HQL 选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7101310/