在HQL查询中从依赖实体中选择属性

时间:2014-05-14 08:47:13

标签: java hibernate hql

我有以下实体:

@Entity
class A {
   @Id
   @GeneratedValue(generator = "system-uuid")
   @GenericGenerator(name = "system-uuid", strategy = "uuid2")
   String id;
        //some field        

   @ManyToMany
   Set<B> other;
}

@Entity
class B {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid2")
    String id;
    //some field
}

我想创建hql查询,列出ids中包含的A实体的B Set<B>

Somethig喜欢(不正确):

select a.other.id from A as a where a.id = :pid

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

select a.other.id from A a join a.other o where a.id = :pid