First of all...I am using Spring Annotations that that handle the session (i.e. session per request model).
I found that if I have the following logic:
Code:
public List<Child> getObjects(...) {
Session s = sessionFactory.getCurrentSession();
Criteria c = s.createCriteria(PARENT.class);
List<PARENT> parents = c.list();
List<Child> children = new ArrayList<Child>();
for (Parent p: parents){
children.add(p.getChild());
}
return children;
now..by the time anything interesting happens on children (it has left the session).hence all children end up being null..
so my question is, is there anyway (PROPER WAY) I can explictly force the loading of the children in this situation.
I know I can do (well at least it appears to be working for me..but it feels like a hack).
Code:
public List<Child> getObjects(...) {
Session s = sessionFactory.getCurrentSession();
Criteria c = s.createCriteria(PARENT.class);
List<PARENT> parents = c.list();
List<Child> children = new ArrayList<Child>();
for (Parent p: parents){
[color=#FF0000]p.getChild().getName()[/color] // i.e. call some/any function on the Child..will force hibernate to load the child.
children.add(p.getChild());
}
return children;
any tips? is there not a way to simply do s.load(p.getChild())...