I have a bunch of Hibernate mapped objects in my Spring MVC app. Default seems to be lazy loading for nested objects with relations. I realized this by getting a lot of errors in my JSP when accessing e.g. a list of children objects.
So I implemented a second method to get a list of objects with all children initliazed. I was wondering if someone could give me some feedback if this was the way to go or not?
This is my code in my DAO implementation that works:
public List<Address> getTripListFullyInitliazed() {
HibernateTemplate template = getHibernateTemplate();
List<Address> addresses = template.loadAll(Address.class);
for (Address address : address) {
template.initialize(address.getChildren());
}
return addresses;
}
Can someone please tell me if this ok to do or if I should change something?