可以使用Hibernate标准吗?
select A.something, B.something, C.something, D.something from A JOIN B on A.id = B.id_fk JOIN C ON B.id = C.id_fk JOIN D ON C.id = D.id_fk;
我遇到了完全相同的问题,并能够像这样解决它:
return criteria.createCriteria(A.class) .createCriteria("b", "join_between_a_b") .createCriteria("c", "join_between_b_c") .createCriteria("d", "join_between_c_d") .add(Restrictions.eq("some_field_of_D", someValue));
注:"b","c"和"d"在上面的代码指在属性名A,B和C类,相应地(类A具有属性b等)。
"b"
"c"
"d"
A
B
C
b
对于此解决方案,您甚至不需要在中设置lazy和fetch参数A.hbm.xml。
lazy
fetch
A.hbm.xml