【发布时间】:2015-03-15 05:51:45
【问题描述】:
我正在尝试构建一个 HQL 查询以从 @ElementCollection 中提取属性:
public class Resource {
@Id
private String name;
@ElementCollection()
@CollectionTable(
name = "property",
)
@SortNatural
private final SortedMap<String, String> properties =
Maps.newTreeMap();
}
property 表使用默认列名(properties 和 properties_key)来存储数据(使用外键返回我的资源表)。
我有以下 HQL 查询,我试图在其中返回键和值。
final Query q = session.createQuery("select new list(r.name, elements(r.properties)) from Resource r where r.name like :nameFilter");
这是有效的,当我调用q.list() 时,我得到一个包含名称和值的对象列表。我遇到的问题是我无法弄清楚如何获取与值关联的键。即properties_key 列中的数据。
我尝试过的事情:
- 元素(r.properties_key)
- 元素(r.propertiesKey)
- 元素(r.key)
这些都不起作用。
是否可以将这些数据取出来?如何确定要在 HQL 查询中使用的属性名称?
【问题讨论】: