我有以下實體:從相關實體中選擇屬性在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
查詢該列表B中的ids
包含在Set<B>
A
實體。
Somethig像(不正確):
select a.other.id from A as a where a.id = :pid
什麼拋出的異常和你是如何從休眠調用它。另見http://stackoverflow.com/questions/11807698/how-to-retrieve-only-certain-fields-of-an-entity-in-jpql-or-hql-what-is-the-equ –