該查詢選擇。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
請發佈完整的堆棧跟蹤。 –