Hello
Thanks for your reply. I was not closing the Hibernate SessionFactory myself i.e. in my code, also there is declarative transaction management in my application.. that is why i never handled the transactions anywhere in the application. But for this indexing method i am calling the session.beginTransacation() and transaction.commit() methods because otherwise the indexes are not committed if i do not commit the transaction. I will paste the relevant portion of my application context file here as well:
Code:
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="txManager"/>
</bean>
<bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor"/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation" value="classpath:/hibernate.cfg.xml"> </property>
</bean>
After reading your reply, i closed the Hibernate SessionFactory after closing the session i.e:
Code:
finally{
session.close();
getSessionFactory().close();
}
After this my program terminates after the completion of method and the indexes are written as well. But now after i run search on the indexed data i get an exception i.e:
Code:
org.apache.lucene.store.AlreadyClosedException: this IndexReader is closed
at org.apache.lucene.index.IndexReader.ensureOpen(IndexReader.java:196)
at org.apache.lucene.index.DirectoryIndexReader.reopen(DirectoryIndexReader.java:143)
at org.hibernate.search.reader.SharingBufferReaderProvider$PerDirectoryLatestReader.refreshAndGet(SharingBufferReaderProvider.java:242)
at org.hibernate.search.reader.SharingBufferReaderProvider.openReader(SharingBufferReaderProvider.java:123)
at org.hibernate.search.query.FullTextQueryImpl.buildSearcher(FullTextQueryImpl.java:718)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:288)
at com.sime.geoserv.server.dao.map.ProjectionDAO.searchResultl(UserDAO.java:249)
at com.sime.geoserv.server.services.MapService.searchResultl(UserService.java:799)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
Here is the search method:
Code:
org.hibernate.Session session = getHibernateTemplate().getSessionFactory().openSession();
String searchQuery = "john";
String[] searchFields = {"name"};
try {
QueryParser parser = new MultiFieldQueryParser(searchFields, new StandardAnalyzer());
org.apache.lucene.search.Query luceneQuery;
luceneQuery = parser.parse(searchQuery);
FullTextSession ftSession = Search.getFullTextSession(session);
org.hibernate.Query query = ftSession.createFullTextQuery(luceneQuery);
List<Layerattribute> results = [color=#FF0000]query.list(); //<----- This is where the exception occurs.
for (Iterator iterator = results.iterator(); iterator.hasNext();) {
User user = (User) iterator.next();
}
}
Can you please guide as to what should be done to solve this issue?