So I traced through the Hibernate Search source to see if I can figure anything out about this error. A couple of observations:
1) From the stack trace:
Code:
org.hibernate.HibernateException: Hibernate Search Event listeners not configured, please check the reference documentation and the application's hibernate.cfg.xml
at org.hibernate.search.util.ContextHelper.getSearchFactoryBySFI(ContextHelper.java:32)
at org.hibernate.search.util.ContextHelper.getSearchFactory(ContextHelper.java:18)
at org.hibernate.search.impl.FullTextSessionImpl.getSearchFactoryImplementor(FullTextSessionImpl.java:160)
at org.hibernate.search.impl.FullTextSessionImpl.index(FullTextSessionImpl.java:134)
at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.index(FullTextEntityManagerImpl.java:65)
The bottom line provided means I am certainly using Hibernate entity manager and JPA. And as it says in the documentation,
"Hibernate Search is enabled out of the box when using Hibernate Annotations or Hibernate EntityManager."
So this suggests I shouldn't need to do anything involving listeners if I am using either of those correctly.
2) Here is the Hibernate Search method in
org.hibernate.search.util.ContextHelper that throws the exception:
Code:
public static SearchFactoryImplementor getSearchFactoryBySFI(SessionImplementor session) {
PostInsertEventListener[] listeners = session.getListeners().getPostInsertEventListeners();
FullTextIndexEventListener listener = null;
//FIXME this sucks since we mandante the event listener use
for ( PostInsertEventListener candidate : listeners ) {
if ( candidate instanceof FullTextIndexEventListener ) {
listener = (FullTextIndexEventListener) candidate;
break;
}
}
if ( listener == null ) throw new HibernateException(
"Hibernate Search Event listeners not configured, please check the reference documentation and the " +
"application's hibernate.cfg.xml" );
return listener.getSearchFactoryImplementor();
}
The SessionImplementor object should have an array of PostInsertEventListeners, but the array is empty. I see how to provide such a thing in the documentation. However, that is supposed to be unnecessary with Hibernate EntityManager. Furthermore, I am unaware how to do the following in a JPA persistence.xml file:
Code:
<event type="post-insert"
<listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
</event>
Anyway, so I have done my homework, and it seems like either there is a bug in the code, or more likely I am missing a simple item in my persistence.xml, or even more likely I am failing to bootstrap something for TestNG in my SeamTest.
If Emmanuel or his team could speak to those possibilities, or if anyone has actually written a TestNG class to test their queries before deploying them, I would appreciate some insight.
Thanks.