FetchMode.SELECT doesn't seem to do anything.
After the query i terminate(commit) the transaction. Followed by a for-loop, looping trough the children resulting in the lazy-instantiation error.
I am now using Hibernate.initialize(..) to load the children.
I created a method which takes the object and uses every get method to initialize whatever is in it.
Code:
private static <T> T initializeChildren(T o) {
Class c = o.getClass();
for (Method m : c.getDeclaredMethods()) {
if (m.getName().startsWith("get")) {
try {
Hibernate.initialize(m.invoke(o, null));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
return o;
}
It'll also go over the non-association getters, but i suppose that's not too bad. Now all i do is, when getting the object pass it to the method and it returns filled and loaded.