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