I am trying to use HIBERNATE Search with the following configuration:
HIBERNATE version: 3.2.6GA
HIBERNATE Search version: 3.1.0GA
HIBERNATE Annotations version: 3.4.0GA
SPRING version: 2.5.6
MySQL version: 5.1.30
Here is the code for the entity class.
Code:
package in.mbaxi.sample.eventtracker.domain;
@Entity
@Table(name = "`ARTICLE`")
@Indexed(index = "Article")
public class Article implements Serializable
{
private static final long serialVersionUID = 2637516829286486607L;
@Column(length = 4000, name = "`DESCRIPTION`")
@Field(index = Index.TOKENIZED, store = Store.NO)
public String description;
@Column(length = 255, name = "`GUID`")
public String guid;
@Id
@Column(name = "`ID`")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@DocumentId
public Long id;
@Column(length = 100, name = "`LINK`")
public String link;
@Column(name = "`PUBLICATION_DATE`")
public Date publicationDate;
@Column(length = 255, name = "`TITLE`")
@Field(index = Index.TOKENIZED, store = Store.NO)
public String title;
...
}
SPRING configuration file is as follows:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
HIBERNATE in-memory C3P0 managed database connection pool.
-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="idleConnectionTestPeriod" value="60" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/eventtracker" />
<property name="maxPoolSize" value="10" />
<property name="maxStatements" value="100" />
<property name="minPoolSize" value="1" />
<property name="password" value="eventtracker" />
<property name="testConnectionOnCheckout" value="false" />
<property name="user" value="eventtracker" />
</bean>
<!--
HIBERNATE Search entity index event listener.
-->
<bean id="searchIndexer" class="org.hibernate.search.event.FullTextIndexEventListener" />
<!--
HIBERNATE SessionFactory object.
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>in.mbaxi.sample.eventtracker.domain.Article</value>
</list>
</property>
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="eventListeners">
<map>
<entry key="post-collection-recreate">
<ref local="searchIndexer" />
</entry>
<entry key="post-collection-remove">
<ref local="searchIndexer" />
</entry>
<entry key="post-collection-update">
<ref local="searchIndexer" />
</entry>
<entry key="post-delete">
<ref local="searchIndexer" />
</entry>
<entry key="post-insert">
<ref local="searchIndexer" />
</entry>
<entry key="post-update">
<ref local="searchIndexer" />
</entry>
</map>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</prop>
<prop key="hibernate.search.default.indexBase">C:/Temp/index</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
</bean>
<!--
A SPRING interceptor that takes care of HIBERNATE session lifecycle.
-->
<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
I am seeing the following behaviour:
1. On attempting to insert a new record of the entity type
Article, the new record is successfully inserted into the database;
2. When the application is compiled and started from scratch, a new folder called
C:/Temp/index/Article is created. This folder contains two files named
segments.gen and
segments_1 respectively. However, neither of these files contains any information about the fields that should be in the index (id, description and title). I have verified this using a Lucene index validation tool such as Luke. The two files have 20 and 28 bytes respectively;
3. Although a database insert works fine, the entity is not indexed at all. No error or exception messages are printed either;
4. On attempting to update a record, the record is updated successfully in the database;
5. Although database updates work fine, index remains empty;
6. If I remove the annotation
@DocumentId, HIBERNATE SessionFactory creation fails saying that a document ID is mandatory for indexing. This shows that HIBERNATE Search is able to see the Search related annotations.
I have the following questions:
* Why are entities not being indexed?
* When the index is first created, why does it not contain information about the fields?[/code]