假设我有以下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 map中的特定键值对匹配。有人可以帮我吗?
提前致谢。
答案 0 :(得分:1)
您需要使用HQL index()
特定函数,该函数适用于已连接索引集合(数组,列表和映射)的别名。请参阅Hibernate参考文档的14.10. Expressions部分
//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'