Hi All,
I am trying to configure Hibernate(3.4), Hibernate Search(3.1.1) and Spring 3.0.0RC1 to make search work. The problem is that the Lucene index is not updated at all when entities are saved, no mater how many I try to save. Here is the relevant configurations.
applicationContext.xmlCode:
<!-- Hibernate session factory -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<constructor-arg index="0" value="${ech.conn.driver}" />
<constructor-arg index="1" value="${ech.conn.url}" />
<constructor-arg index="2" value="${ech.conn.username}" />
<constructor-arg index="3" value="${ech.conn.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
hibernate.cfg.xmlCode:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">${ech.db.dialect}</property>
<!-- Hibernate Search configuration -->
<property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
<property name="hibernate.search.default.indexBase">c:/temp/lucene/indexes</property>
<!-- this will show us all SQL statements -->
<property name="hibernate.show_sql">true</property>
<mapping class="au.com.cgu.echelon.domain.sandbox.Address" />
<mapping class="au.com.cgu.echelon.domain.sandbox.TestPolicy"></mapping>
<mapping class="au.com.cgu.echelon.domain.sandbox.TestBroker" />
<mapping class="au.com.cgu.echelon.domain.sandbox.TestInterestInsured" />
<mapping class="au.com.cgu.echelon.domain.UserProfile" />
</session-factory>
</hibernate-configuration>
TestPolicy.javaCode:
@Entity
@Table( name = "SB_POLICY" )
@Indexed( index = "policies" )
public class TestPolicy implements Serializable, IImmortal
{
private static final long serialVersionUID = 1L;
@ManyToOne( cascade = CascadeType.ALL )
@JoinColumn( name = "Broker_Id" )
private TestBroker _broker;
@OneToMany( cascade = CascadeType.ALL, fetch = FetchType.EAGER )
@JoinColumn( name = "Policy_Id" )
private List< TestInterestInsured > _interestInsureds = new ArrayList< TestInterestInsured >();
@Column( name = "Policy_Number" )
@Field( name = "policyNumber" )
private String _policyNumber;
@Id
@Column( name = "Policy_Id" )
@SequenceGenerator( name = "Policy_Sequence", sequenceName = "ECHELON.SQ_Policy", allocationSize = 10 )
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "Policy_Sequence" )
@DocumentId
private int _policyId;
// Getters and Setters omitted
}
Here is the code that stores the policy:
Code:
@Transactional(propagation=Propagation.REQUIRES_NEW)
public TestPolicy storePolicy( final TestPolicy policy )
{
getCurrentSession().saveOrUpdate( policy );
getCurrentSession().flush();
return policy;
}
Now, the hibernate bits work just fine and TestPolicy objects get saved to the database. However the lucene index is NOT updated after the flush (or after the transaction is completed). What am I doing wrong to make the indexes auto update? The configuration that I have should support automatic registration of FullTextIndexListener, but I've tried to register them manually to no avail. Please help.