该查询选择。HQL从多个表
然而,当我遍历儿童List
我就行了这个循环for (int j = 0; j < allParent.get(i).getAllChild().size(); j++) {
得到java.lang.ClassCastException
:
for (int i = 0; i < allParent.size(); i++) {
System.out.println(allParent.get(i));
for (int j = 0; j < allParent.get(i).getAllChild().size(); j++) {
System.out.println("Child: " + allParent.get(i).getAllChild().get(j).getID());
}
HibernateUtil.getSessionFactory().getCurrentSession().flush();
HibernateUtil.getSessionFactory().getCurrentSession().clear();
}
Parent.hbm.xml
<bag name="allChild" table="child" inverse="true" lazy="true" fetch="select">
<key property-ref="surname">
<column name="surname" not-null="true" />
</key>
<one-to-many class="com.test.Child" />
</bag>
有没有一种方法,我可以使用Criteria
(或别的东西)来运行此语句,而不是使用它填充allParent
List
和allChild
List
链接到allParent
之内的每个Parent
?
是child_id字符串变量,如果您显示模型类,它也会对我们更有帮助 – harrybvp
请发布完整的堆栈跟踪。 –