Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.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 从@ElementCollection获取字段的HQL查询_Java_Hibernate_Hql - Fatal编程技术网

Java 从@ElementCollection获取字段的HQL查询

Java 从@ElementCollection获取字段的HQL查询,java,hibernate,hql,Java,Hibernate,Hql,我正在尝试构造一个HQL查询,以从@ElementCollection中提取属性: public class Resource { @Id private String name; @ElementCollection() @CollectionTable( name = "property", ) @SortNatural private final SortedMap<String, String> propert

我正在尝试构造一个HQL查询,以从@ElementCollection中提取属性:

public class Resource {
  @Id
  private String name;

  @ElementCollection()
  @CollectionTable(
          name = "property",
          )
  @SortNatural
  private final SortedMap<String, String> properties =
        Maps.newTreeMap();
}
这是可行的,当我调用
q.list()
时,我会得到一个包含名称和值的对象列表。我遇到的问题是,我不知道如何获取与值关联的键。i、 e.
properties\u键
列中的数据

我尝试过的事情:

  • 元素(r.properties\u键)
  • 元素(r.propertiesKey)
  • 元素(右键)
  • 这些都不管用


    有可能把这些数据拿出来吗?如何计算要在HQL查询中使用的属性的名称?

    加入集合,然后使用index()获取密钥。
    索引(p)是关键,而p是值

    List list = currentSession.createQuery(
    "select new list(s.id, index(p), p) from Resource s join s.properties p").list();
    

    非常感谢你,我遇到了完全相同的问题,这就是我的解决方案。这完全是晦涩难懂的!
    List list = currentSession.createQuery(
    "select new list(s.id, index(p), p) from Resource s join s.properties p").list();