|
From: James C. <jim...@do...> - 2004-03-02 20:36:22
|
I think I am missing some basic lifecycle method, but I have read the docs and maybe it does not exist? I have a cyclic relationship between two beans: <bean id="CategoryDAO" class="my.CategoryDAOHibernate"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> <property name="categoryHierarchy"> <ref local="CategoryHierarchy"/> </property> </bean> <bean id="CategoryHierarchy" class="my.CategoryHierarchy"> <property name="categoryDAO"> <ref local="CategoryDAO"/> </property> </bean> CategoryDAO extends HibernateDaoSupport, so it's afterPropertiesSet() method uses the session factory to initialize the DAO which creates a hibernate template. The CategoryHierarchy is not a database-aware object and it uses the CategoryDAO object for any data-access it may need. The problem is in the afterPropertiesSet() method on the CategoryHierarchy object. This is where I decided to make a call to the CateogryDAO and get some data that the CategoryHierarchy object needs. Unfortunately, I get a NullPointerException because the CategoryDAO object has yet to have its afterPropertiesSet method invoked. This method sets up the HibernateTemplate object. It is null, thus my NPE. Here is the order I am seeing: 1. CategoryDAO <init> 2. CategortHierarchy <init> 3. CategoryHierarchy.setCategoryDAO(o) 4. CategoryHierarchy.afterPropertiesSet() - NPE because it makes a call using CategoryDAO object 5. CategoryDAO.setSessionFactory(o) 6. CategoryDAO.setCategoryHierarchy(o) 7. CategoryDAO.afterPropertiesSet() - CategoryDAO can only answer calls after this step Is there a lifecycle event that fires *after* the factory has configured all of the static beans including all aop bindings? I have tried the 'init-method' attribute on the bean. It seems to fire before afterPropertiesSet. I have tried the BeanFactoryAware interface, but it still fires pretty early. Is there an event that is triggered after the factory wires up everything? |