java版的實際例子。類同妳說的情況
private void findChildList(AssetType parent,List<AssetType> list){
String hql = "from AssetType a where a.parentAssetType.assetTypeId=? ORDER BY a.sort,a.assetTypeName asc";
List<AssetType> childList = this.assetTypeDao
.getEntityManager()
.createQuery(hql)
.setParameter(1, parent.getAssetTypeId())
.getResultList();
int size = childList.size();
if(size>0){
for (int i = 0; i < size; i++) {
AssetType assetType = childList.get(i);
List<AssetType> childs = assetType.getChildAssetType();
if(childs.size()>0){
list.addAll(childs);
this.findChildList(assetType, list);//遞歸查詢節點的子節點
}
}
}
}