【发布时间】:2015-10-07 15:57:07
【问题描述】:
我想在一个特定 MapKey 条目的 Map 属性上使用连接来测试查询,但我还没有找到解决方案。有没有人完成过这样的查询并可以共享正确的 JPQL / HQL?
MapKey 列是enum 类型,值是另一个@Entity。
这是模型:
@Entity
public class Operation {
@Id
private int id;
@OneToMany(mappedBy = "operation", fetch = FetchType.LAZY)
@Cascade(CascadeType.ALL)
@MapKeyEnumerated(EnumType.STRING)
private Map<OperationDetailsType, OperationDetails> operationDetails;
}
@Entity
public class OperationDetails {
@Id
private int id;
private String details;
}
public enum OperationDetailsType { SHORT, FULL }
这是我目前尝试过的查询:
SELECT operation FROM Operation operation join operation.operationDetails['SHORT'] operationDetailsShort WHERE operationDetailsShort.details = :el1
我在 Hibernate Community 中找到了这个参考,但是使用 [...] 的方法会引发错误:
https://forum.hibernate.org/viewtopic.php?f=1&t=1004884
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: [ near line 1,...
休眠版本是:4.3.8.Final
谢谢
【问题讨论】: