-->
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: JDBCTransaction when perform indexing
PostPosted: Tue Jun 30, 2009 3:34 am 
Newbie

Joined: Thu Jun 25, 2009 4:50 am
Posts: 7
Hi,

My project is currently working on hibernateSearch with Spring framework. I'm currently stuck on the simple indexing part. Below are the code I used for indexing:

Code:
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.search.FullTextSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import domain.Mrconso;

public class Indexer {

        //sessionFactory is being injected by the spring configuration
   private SessionFactory sessionFactory;
   
   public void setSessionFactory(SessionFactory sessionFactory) {
      this.sessionFactory = sessionFactory;
   }

   public void index() {
      Session session = sessionFactory.openSession();
      FullTextSession ftSession = org.hibernate.search.Search
            .getFullTextSession(session);

      Transaction tx = ftSession.beginTransaction();

      @SuppressWarnings("unchecked")
      List<Mrconso> mrconsos = session.createCriteria(Mrconso.class)
            .list();
      for (Mrconso mrconso : mrconsos) {
         ftSession.index(mrconso);
      }

      tx.commit();
      session.close();
   }

   /**
    * @param args
    */
   public static void main(String[] args) {
      String[] configLocation = new String[] { "data.xml",
            "data-hibernate.xml" };
      ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocation);
      Indexer indexer = (Indexer) ctx.getBean("indexer");
      indexer.index();
   }
}


This is my data.xml (used to define dataSource)
Code:
<bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${db.driver}" />
    <property name="url" value="${db.url}" />
    <property name="username" value="${db.username}" />
    <property name="password" value="${db.password}" />
    <property name="initialSize" value="${db.initialSize}" />
    <property name="maxActive" value="${db.maxActive}" />
  </bean>


And this is the data-hibernate.xml (used to define indexer, dao and sessionFactory)
Code:
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="annotatedClasses">
        <list>
          <value>domain.Mrconso</value>
        </list>
      </property>
      <property name="hibernateProperties">
        <props>
         <prop key="hibernate.dialect">${db.dialect}</prop>
         
         <!-- Hibernate Search configuration -->
         <prop key="hibernate.search.default.directory_provider">
           org.hibernate.search.store.FSDirectoryProvider
         </prop>
         <prop key="hibernate.search.default.indexBase">/WEB-INF/indexes</prop>
         </props>
      </property>
  </bean>
 
  <bean id="indexer" class="Indexer">
     <property name="sessionFactory" ref="sessionFactory"/>
  </bean>


When I tried to run the main method, I've got the errors as below:

Code:
[ERROR] 15:05:01 JDBCTransaction - exception calling user Synchronization
java.lang.NoSuchFieldError: NOT_ANALYZED
   at org.hibernate.search.engine.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:361)
   at org.hibernate.search.engine.DocumentBuilderIndexedEntity.createAddWork(DocumentBuilderIndexedEntity.java:328)
   at org.hibernate.search.engine.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:317)
   at org.hibernate.search.backend.impl.BatchedQueueingProcessor.addWorkToBuilderQueue(BatchedQueueingProcessor.java:153)
   at org.hibernate.search.backend.impl.BatchedQueueingProcessor.processWorkByLayer(BatchedQueueingProcessor.java:140)
   at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:128)
   at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:47)
   at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:228)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:109)
   at Indexer.index(DisonIndexer.java:65)
   at Indexer.main(DisonIndexer.java:78)
[ERROR] 15:05:01 AssertionFailure - an assertion failure occured (this may indicate a bug in Hibernate)
org.hibernate.annotations.common.AssertionFailure: Access a Sealed WorkQueue which has not been sealed
   at org.hibernate.search.backend.WorkQueue.getSealedQueue(WorkQueue.java:47)
   at org.hibernate.search.backend.impl.BatchedQueueingProcessor.performWorks(BatchedQueueingProcessor.java:170)
   at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.afterCompletion(PostTransactionWorkQueueSynchronization.java:53)
   at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsAfterTransactionCompletion(JDBCTransaction.java:243)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:121)
   at Indexer.index(DisonIndexer.java:65)
   at Indexer.main(Indexer.java:78)
[ERROR] 15:05:01 JDBCTransaction - exception calling user Synchronization
org.hibernate.annotations.common.AssertionFailure: Access a Sealed WorkQueue which has not been sealed
   at org.hibernate.search.backend.WorkQueue.getSealedQueue(WorkQueue.java:47)
   at org.hibernate.search.backend.impl.BatchedQueueingProcessor.performWorks(BatchedQueueingProcessor.java:170)
   at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.afterCompletion(PostTransactionWorkQueueSynchronization.java:53)
   at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsAfterTransactionCompletion(JDBCTransaction.java:243)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:121)
   at Indexer.index(DisonIndexer.java:65)
   at Indexer.main(Indexer.java:78)



May I know if I have missed anything on the setting pls? Pls render me your help so that I can proceed with the query part. Thanks alot.

Regards,
Joon


Top
 Profile  
 
 Post subject: Re: Hibernate Search: JDBCTransaction when perform indexing
PostPosted: Tue Jun 30, 2009 10:48 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I think you're hitting HSEARCH-380
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-380

using maven to define the classpath?
make sure you remove solr-lucene-core.jar from your classpath, and no other versions of Lucene around.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search: JDBCTransaction when perform indexing
PostPosted: Tue Jun 30, 2009 11:17 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
And lookout for memory usage, you're loading all entities in memory as you never clear the session during the indexing...
this is ok you know for sure the number of entities is limited, otherwise there's better code shown in the reference docs.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search: JDBCTransaction when perform indexing
PostPosted: Tue Jun 30, 2009 11:50 am 
Newbie

Joined: Thu Jun 25, 2009 4:50 am
Posts: 7
Hi Sanne,

Thank you very much for your advice and pointer. It does resolve the exception now.

Yes, I'm using Maven to define the dependency. So I've just include an exclusion to the solr-core (as below):
Code:
<dependency>
         <groupId>org.apache.solr</groupId>
         <artifactId>solr-core</artifactId>
         <version>1.3.0</version>
         <exclusions>
           <exclusion>
             <groupId>org.apache.solr</groupId>
             <artifactId>solr-lucene-core</artifactId>
           </exclusion>
         </exclusions>
      </dependency>


Yeah, I'll be trying on the ScrollableResults to perform the indexing later. Thanks for your reminder.

Regards,
Joon


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.