Spring + Hibernate Search 3.1.0 = ArrayStoreException

Posted by Double Compile. Tuesday, January 19. 2010, 11:30 AM in Java

I'm using Spring Framework version 3.0.0 (although, I'll bet the same problem would happen with 2.x). I'm using Hibernate Search 3.1.0 (That's what's in Maven. I wonder why there's no 3.1.1).

Trying to use the configuration as follows inside of a Spring configuration document.

<property name="eventListeners">
<map>
<entry key="post-update" value-ref="fullTextEventListener" />
<entry key="post-delete" value-ref="fullTextEventListener" />
<entry key="post-insert" value-ref="fullTextEventListener" />
<entry key="flush">
<list>
<bean class="org.hibernate.event.def.DefaultFlushEventListener" />
<ref local="fullTextEventListener" />
</list>
</entry>
</map>
</property>

Upon running some unit tests, I get a nasty Exception stack, with the following at the root.

Caused by: java.lang.ArrayStoreException
	at java.lang.System.arraycopy(Native Method)
	at java.util.ArrayList.toArray(ArrayList.java:306)
	at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:759)
	at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
	... 57 more

The root cause of the problem (and I needed to debug the Spring/Hibernate internals to figure this out) is that FullTextIndexEventListener does not implement the FlushEventListener interface in version 3.1.0, but it does in 3.1.1.

Solution: upgrade (if you're using Maven, try the JBoss repository which has the latest stuff) or omit the "flush" event from the configuration.

Dependency Injection in Xyster

Posted by Double Compile. Monday, December 10. 2007, 04:41 PM in Xyster

Inversion of Control is one of those design patterns that once you "get it", you'll start seeing that it can be applied basically all over the place. It's the lesson of "tell; don't ask".

I've spent a good deal of time this weekend with the Xyster incubator; creating a Dependency Injection package called Xyster_Container based almost entirely on PicoContainer. The good: PHP method signatures are much more simple than Java's; only one constructor per class. The bad: PHP scalar method parameters are not typed, so you cannot use ReflectionParameter::getClass() on them. This first release won't support the LifeCycle capabilities or annotations, but at least annotations support is planned (remember, it's still in the incubator).

This Dependency Injection package will be used to replace/redo the Xyster_Application package. You'll read in Fowler's article (linked above) about the Service Locater concept, which was what Xyster_Application was intended to be. While the Locater might still be done, I think it's more important that application services can be injected into the classes that use them.

For now, read up on Dependency Injection. You'll wonder where it's been all your life.

Defined tags for this entry: , , , ,