-->
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.  [ 5 posts ] 
Author Message
 Post subject: HIBERNATE Search not indexing entities
PostPosted: Fri Apr 03, 2009 5:41 am 
Newbie

Joined: Fri Apr 03, 2009 5:24 am
Posts: 3
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]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 6:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

the most common problem we've seen when using Hibernate Search with Spring is a wrongly configured transaction configuration. Search this forum for Spring and transaction and you will find a lot of information. In fact i cannot see how you handle transactions at all in your configuration/code.
It would also help to see your indexing/persisting code.

The index does not contain any information, because no Document has been inserted yet. The index does not care what fields the added Lucene documents have. In fact you can add documents with completely different set of fields. This means of course that there is no meta information available for an empty index.

Regarding @DocumentId - it should be optional since you are using entity manager. Are you sure that you are working with the latest release of Search? Also the explicit configuration of the even listeners should no be required. If you use entity manager and have Hibernate Search in the class path the listeners are configured automatically.

Last but not least - maybe this helps http://www.hibernate.org/441.html

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 6:31 am 
Newbie

Joined: Fri Apr 03, 2009 5:24 am
Posts: 3
Hi Hardy

Many thanks for the quick reply. I have pasted the entire SPRING configuration file below.

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>

    <!--
        Data access objects.
    -->
    <bean id="articleDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target">
            <bean class="in.mbaxi.sample.eventtracker.data.ArticleDatabaseDAO">
                <property name="sessionFactory">
                    <ref local="sessionFactory" />
                </property>
            </bean>
        </property>
        <property name="proxyInterfaces">
            <value>in.mbaxi.sample.eventtracker.data.ArticleDAO</value>
        </property>
        <property name="interceptorNames">
            <list>
                <value>hibernateInterceptor</value>
            </list>
        </property>
    </bean>

    <!--
        A SPRING interceptor that takes care of database transactions.
    -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

    <!--
        A SPRING interceptor that takes care of database transactions.
    -->
    <bean id="serviceTransactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
        <property name="transactionAttributeSource">
            <value>in.mbaxi.sample.eventtracker.service.ArticleService.saveArticles=PROPAGATION_REQUIRED</value>
        </property>
    </bean>

    <!--
        Service objects.
    -->
    <bean id="articleService" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="target">
            <bean class="in.mbaxi.sample.eventtracker.service.ArticleServiceImpl">
                <property name="articleDAO">
                    <ref bean="articleDAO" />
                </property>
            </bean>
        </property>
        <property name="proxyInterfaces">
            <value>in.mbaxi.sample.eventtracker.service.ArticleService</value>
        </property>
        <property name="interceptorNames">
            <list>
                <value>serviceTransactionInterceptor</value>
                <value>hibernateInterceptor</value>
            </list>
        </property>
    </bean>
</beans>



Then, I simply load the SPRING context using
Code:
org.springframework.context.support.ClassPathXmlApplicationContext
and obtain
Code:
articleService
from it.
Code:
articleService
calls
Code:
articleDAO
in turn, which simply does a
Code:
getHibernateTemplate().saveOrUpdate(entity)
.

Do you think the
Code:
DataSourceTransactionManager
could be causing a problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 7:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I am actually pretty sure that it is a transaction problem. However, I am not a Spring expert and I haven't seen the setup you are using. I am normally using the annotation based transaction management.

I recommend you turn on debug trace for spring and hibernate and see if you can see what's going on. Of special interest are all transaction related log messages.

Also have a look at http://forum.hibernate.org/viewtopic.php?t=988828

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 9:24 am 
Newbie

Joined: Fri Apr 03, 2009 5:24 am
Posts: 3
Hi Hardy

I looked through your post and tried using SPRING provided
Code:
HibernateTransactionManager
. Now, running my test cases is updating the index properly. I am now going to try changing the configuration for my actual Production application which runs as a Quartz-based WAR.

Thanks a lot for your help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.