Ok I seem to be making some progress. Sometimes you try to make things more difficult than they need to be.
Within a method of my DAO
Code:
Session session = getHibernateTemplate().getSessionFactory().openSession();
Transaction tran = session.beginTransaction();
List sites = session.find("from SiteConfig siteConfig " +
"left join fetch siteConfig.routers router " +
"left join fetch router.interfaces interfaces " +
"where interfaces.monitored = ?", Boolean.TRUE, Hibernate.BOOLEAN);
for (int i = 0; i < sites.size(); i++) {
ISiteConfig siteConfig = (ISiteConfig) sites.get(i);
List routers = siteConfig.getRouters();
for (int j = 0; j < routers.size(); j++) {
IRouterConfig routerConfig = (IRouterConfig) routers.get(j);
routerConfig.getInterfaces().size();
}
}
tran.commit();
session.close();
return sites;
I am no longer getting the LazyInitializationException. Now I need to figure out why in my test I'm getting three interfaces (two of which are null) for a given router when there is only one associated interface in the database. I guess I need to dig into Hibernate some more.