我使用的是Hibernate 4.2版
我有2个实体 .
@Entity
public class A {
Long Id;
@ManyToOne
B b;
}
@Entity
public class B {
Long Id;
//There is no relation back here with any annotations to A, and can't add a @OneToMany
}
是否有可能使用Hibernate Criteria进行查询以获得看起来像这样的结果 .
List<Map<B,List<A>>> ?无论是加入还是选择都无关紧要 .
例如我想要的结果:
A.id B.id
1 1,2,3,4
2
3 5
4 7
5
// Trind
2 回答
你可以使用下面的东西 . 我不知道这是否是你的实际要求 . 假设B b是OneToOne,12是B的id,
这将返回一个数组列表,通过使用这些数组,您可以形成您想要的数组 .
我得到了Christian Bauer的帮助,他写了Hibernate in Action .
来自Hibernate的标准: