Jay2008 (8) [Avatar] Offline
#1
When i place the @Index annotation on my entity i get the following exception from Spring:

Caused by: org.hibernate.AssertionFailure: could not init listeners
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:199)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1315)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1304)

I am assuming these are the listeners that update the Lucene Index when deleting, updating, adding an indexable entity? I have searched the and found the example:

<bean id="sessionFactory" >
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="annotatedClasses">
<list>
<value>us.mikedesjardins.persisted.Cheese</value>
<value>us.mikedesjardins.persisted.Milk</value>
<value>us.mikedesjardins.persisted.Origin</value>
<value>us.mikedesjardins.persisted.Texture</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.search.default.indexBase">/home/iuliana/lucene/index</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop>
</props>
</property>
<property name="eventListeners">
<map>
<entry key="post-update">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
<entry key="post-insert">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
<entry key="post-delete">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
</map>
</property>

</bean>


But the exception is still being thrown. What is the correct way to register the relevant hibernate event listeners with spring?

Many thanks
Jeremy
emmanuel.bernard (101) [Avatar] Offline
#2
Re: how to integrate spring 2.5.5 with hibernate search
which version of hibernate core, and search are you using?
Jay2008 (8) [Avatar] Offline
#3
Re: how to integrate spring 2.5.5 with hibernate search
I'm using Hibernate Search 3.0.1, Hibernate Core 3.3.0.

I figured out through testing that the @Index is ok. The problem is with the @Analyzer annotaton:

@Indexed
@Analyzer(impl = SnowballAnalyzer.class)
public class ZProduct implements java.io.Serializable {
.
.

If i set this to: @Analyzer(impl = StandardAnalyzer.class) then it's ok and no errors occur. So how do i configure the use of the SnowballAnalyzer?

I am using lucene-snowball-2.3.0.jar for this analyzer.

Many thanks for your time
Jeremy
john.griffin (36) [Avatar] Offline
#4
Re: how to integrate spring 2.5.5 with hibernate search
Jeremy,

This looks like a Jira issue to me. What do you think Emmanuel?

Would you open an issue at http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH, please.

Thanks,

John G.
emmanuel.bernard (101) [Avatar] Offline
#5
Re: how to integrate spring 2.5.5 with hibernate search
You have hit
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3261
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3260

which hide the underlying exception. Both are fixed in the new Hibernate Core 3.3.0.CR2 version. Give it a try.

for you actual problem, I think you use the vanilla SnowballAnalyzer (provided by Lucene). It does not have an no-arg constructor and hence the exceptions.
Two solutions:
- write a special SnowballAnalyzer with a no arg constructor delegating to the real one
- use Hibernate Search 3.1 (Beta1 at the moment)

Hibernate Search 3.1 (which has been designed to work with Hibernate Core 3.3) does support a neat notion

@AnalyzerDef(name="englishSnowball",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class ),
filters = { @TokenFilterDef(factory = StandardFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class,
params = @Parameter(name="language",
value="English" ) ) }
)

...

@Field( index = Index.TOKENIZED, store = Store.YES )
@Analyzer(definition="englishSnowball")
private String text;


If you can jump onto the 3.1 wagon.

PS: be careful about this bug http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-232
We are working with the Solr team to get that sorted out. In the mean time you need to full Solr JAR.
emmanuel.bernard (101) [Avatar] Offline
#6
Re: how to integrate spring 2.5.5 with hibernate search
Forgot to say the analyzer def feature and analyzers are descriped in section 5.3 of Hibernate Search in Action
bpmm (34) [Avatar] Offline
#7
org.hibernate.search.event.FullTextIndexEventListener
Hi,
I am working on the indexations fields and I have a problem which to capture event listeners during run my application, although the configuration has been done with this file applicationContext-dev.xml.
Thanks!
bpmm (34) [Avatar] Offline
#8
hibernate search
Hi,
I am looking solutions on querying and exactlly to know hibernate search used his technic to process a query. Example, I want to search on database two names such as TOM and JOHN, what's the operators used either OR, either AND or parenthesis to select words or sentences...?
I hope to solve this situation and obtain help.
Thanks