Hi,
I'm using Hibernate/Spring through Appfuse and since Appfuse "hides" the sessionFactory, I have to use some tricks to register the search event handlers. However, it seems that this works. Debugging it, I can see that they are registered but they are not firing. I think this is because Appfuse uses the merge method to save objects and these dont seem to fire the insert/update events?
Hibernate version:3.2.6.ga
Code:
public class HibernateExtensionPostProcessor extends
org.appfuse.dao.spring.HibernateExtensionPostProcessor {
private Map eventListeners;
private String sessionFactoryBeanName = "sessionFactory";
/**
* Top level properties to add to the session factory.
*
* @param eventListeners
* The list of additional properties.
*/
public void setEventListeners(Map eventListeners) {
this.eventListeners = eventListeners;
}
@SuppressWarnings("unchecked")
public void postProcessBeanFactory(
ConfigurableListableBeanFactory configurableListableBeanFactory) {
if (configurableListableBeanFactory
.containsBean(sessionFactoryBeanName)) {
BeanDefinition sessionFactoryBeanDefinition = configurableListableBeanFactory
.getBeanDefinition(sessionFactoryBeanName);
MutablePropertyValues propertyValues = sessionFactoryBeanDefinition
.getPropertyValues();
if (eventListeners != null) {
PropertyValue propertyValue = propertyValues
.getPropertyValue("eventListeners");
if (propertyValue == null) {
propertyValue = new PropertyValue("eventListeners",
new HashMap());
propertyValues.addPropertyValue(propertyValue);
}
// loop over properties List and add top level property for each entry
Map existingListeners = (Map) propertyValue.getValue();
existingListeners.putAll(eventListeners);
}
}
}
}
Code:
<bean id="textIndexEventListener"
class="org.hibernate.search.event.FullTextIndexEventListener" />
<bean
class="nl.myproject.dao.hibernate.HibernateExtensionPostProcessor">
<property name="eventListeners">
<map>
<entry key="post-update"><ref local="textIndexEventListener" /></entry>
<entry key="post-insert"><ref local="textIndexEventListener" /></entry>
<entry key="post-delete"><ref local="textIndexEventListener" /></entry>
</map>
</property>
</bean>
Any idea why the events are firing?
Cheers.
Marc
[/code]