Java 在HQL查询中从依赖实体中选择属性
我有以下实体:Java 在HQL查询中从依赖实体中选择属性,java,hibernate,hql,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 { @
@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
}
试着这样做:
select a.other.id from A a join a.other o where a.id = :pid
你试过了吗?我不确定,但我认为您应该在投影中使用别名(因此
select o.id…
)。不,我没有测试它,这是我认为我记得的,对不起。引发了什么异常,您如何从hibernate调用它。另见
select a.other.id from A a join a.other o where a.id = :pid