2

Indexing of new elements not working with Hibernate + Spring. No errors are displayed in logs.

Hibernate and Spring versions:

  • Hibernate 4.1.0.Final
  • Hibernate Search 4.0.0.Final
  • Hibernate EntityManager 4.0.1.Final
  • Spring 3.1.1.RELEASE

Spring-context.xml

<bean id="dataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource">
        <ref local="mainDataSource" />
    </property>
</bean>

<bean id="mainDataSource" class="com.jolbox.bonecp.BoneCPDataSource" destroy-method="close">
    <property name="driverClass" value="${jdbc.driver}" />
    <property name="jdbcUrl" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>

    <property name="idleConnectionTestPeriodInMinutes" value="${jdbc.idleConnectionTestPeriodInMinutes}"/>
    <property name="idleMaxAgeInMinutes" value="${jdbc.idleMaxAgeInMinutes}"/>      
    <property name="maxConnectionsPerPartition" value="${jdbc.maxConnectionsPerPartition}"/>
    <property name="minConnectionsPerPartition" value="${jdbc.minConnectionsPerPartition}"/>
    <property name="partitionCount" value="${jdbc.partitionCount}"/>
    <property name="acquireIncrement" value="${jdbc.acquireIncrement}"/>                              
    <property name="statementsCacheSize" value="${jdbc.statementsCacheSize}"/>
    <property name="releaseHelperThreads" value="${jdbc.releaseHelperThreads}"/>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">none</prop>

            <prop key="hibernate.connection.release_mode">auto</prop>
            <prop key="hibernate.auto_close_session">true</prop>


            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>

            <!-- Hibernate search - lucene -->
            <prop key="hibernate.search.default.directory_provider">filesystem</prop>
            <prop key="hibernate.search.default.indexBase">/temp/lucene</prop>
        </props>
    </property>
    <property name="packagesToScan" value="com.example.domain" />
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

Code fragment of class to be indexed

@Indexed
@Entity
@Table(name = "table_name")
public class VideoInfo implements Serializable {
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    @Column(name = "title")
    @Field(index=Index.YES, store=Store.NO)
    private String title;

    @Column(name = "tags")
    @Field(index=Index.YES, store=Store.NO)
    private String tags;

    @Column(name = "url")
    private String url;
....

DAO save method (factory === sessionFactory bean)

factory.getCurrentSession().save(obj);

What could be the problem? Right now I am just a bit confused of what I should actually do, so please help me :)

EDIT: Finally rebuilding the index things began to work properly.

dmunozfer
  • 550
  • 1
  • 5
  • 16
  • How do you know the new objects are not being indexed? What are the symptoms? – madth3 Mar 25 '12 at 18:03
  • Performing a search can not find new items, only those that existed before creating the index. In addition, the index files are not updated (date not modified). – dmunozfer Mar 25 '12 at 19:44
  • did you try inserting one row manually and check if indexes are working. It not sure if your problem is related to hibernate. – ManuPK Mar 26 '12 at 11:01
  • I made a basic example with same config and its working fine. Could be a problem with large databases? (indexing 700k elements) Does the index could be corrupted and for that reason do not insert new elements in it? (search works). Thanks. – dmunozfer Mar 27 '12 at 10:23

1 Answers1

2

I have the same problem but with hibernate 4.1, Envers and EJB 3. I solved it with the annotation @TransactionAttribute to managed the transaction. The Envers listener dont start if the transaction doesn't "normal end". I hope it will help (sorry for my english)

Kevin
  • 19
  • 2