-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Search automatic indexing problems
PostPosted: Wed Nov 18, 2009 1:51 am 
Newbie

Joined: Wed Nov 18, 2009 1:38 am
Posts: 2
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.xml
Code:
<!-- 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.xml
Code:
<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.java
Code:
@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.


Top
 Profile  
 
 Post subject: Re: Hibernate Search automatic indexing problems
PostPosted: Wed Nov 18, 2009 7:19 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
I can't see anything obvious that stands out. I had a similar problem when using Hibernate Search and Spring managed JTA where updates where being made to the database but not to the lucene index. We added the jtaTransactionManager to the sessionfactory which resolved the problem.

How are you testing this? Do you have a integration test using Spring? If you are using this in a Spring integration test then it could be that the tx is being committed and it's been rolled back. The other thing you can do is try to debug and see if any of the Hibernate Search classes are being called.

If you can provide info on how you are testing this then I might be able to suggest what is happening.

Cheers


Top
 Profile  
 
 Post subject: Re: Hibernate Search automatic indexing problems
PostPosted: Wed Nov 18, 2009 9:04 am 
Newbie

Joined: Wed Nov 18, 2009 1:38 am
Posts: 2
Thanks for the reply. This is running in a small app on Jetty, so I don't think JTA Transaction manager is appropriate. The TestPolicy entity is being saved to the database properly and I can see in the logs HibernateTransactionManager initiating the commit and finalising it and calling the beforeCompletion and afterCompletion synchronisations in Hibernate. Looking through the Hibernate Search code I can see that indexing is supposed to occur in the afterCompletion synchronization, but I don't think it runs. I'm starting to wonder if it's not my configuration, then maybe a bug in Spring 3.0.0RC1!?


Top
 Profile  
 
 Post subject: Re: Hibernate Search automatic indexing problems
PostPosted: Wed Nov 18, 2009 10:11 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Our use apps required JTA that is why i mentioned it. I wouldn't recommend JTA unless you really needed it. Is it worth trying the same thing with Spring 2.5? I haven't developed it with Spring 3.0. I haven't had any issues with using Hibernate Search 3.1.1 and Spring 2.5 (we are deploying HS next week). Configuration wise I presume you added the FullTextEventIndexListeners to the sessionfactory using eventlisteners property?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.