}
return result;
}
private OrderElement orderFrom(OrderElement initial) {
OrderElement current = initial;
OrderElement result = current;
while (current != null) {
result = current;
current = findParent(current);
}
return result;
}
private OrderElement findParent(OrderElement orderElement) {
Query query = getSession()
.createQuery(
"select e.parent from OrderElement e where e.id = :id")
.setParameter("id", orderElement.getId());
return (OrderElement) query.uniqueResult();
}
});
List<Order> result = new ArrayList<Order>();
for (OrderElement each : orders) {
if (each != null) {
result.add(findExistingEntity(each.getId()));
} else {
result.add(null);
}
}
return result;
}