Hi ,I'm using hibernate search to study full text search. When I run my first app, I got the error below:
Exception in thread "main" org.hibernate.HibernateException: getListeners is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy9.getListeners(Unknown Source)
at org.hibernate.search.backend.impl.EventSourceTransactionContext.getIndexWorkFlushEventListener(EventSourceTransactionContext.java:78)
at org.hibernate.search.backend.impl.EventSourceTransactionContext.<init>(EventSourceTransactionContext.java:41)
at org.hibernate.search.impl.FullTextSessionImpl.<init>(FullTextSessionImpl.java:75)
at org.hibernate.search.Search.getFullTextSession(Search.java:23)
at com.v512.examples.HibernateSearchTest.indexGuestbook(HibernateSearchTest.java:17)
at com.v512.examples.HibernateSearchTest.main(HibernateSearchTest.java:59)
my app:
Code:
Session session = HibernateSessionFactoryUtil.getSessionFactory().getCurrentSession();
FullTextSession ftSession = org.hibernate.search.Search.getFullTextSession(session);//this line cause the above error!!!!
ftSession.getTransaction().begin();
List<Guestbook> guestbooks = session.createQuery("from Guestbook").list();
for (Guestbook gb : guestbooks) {
ftSession.index(gb); // 手工方式,把所有持久化对象进行索引
}
ftSession.getTransaction().commit();
hibernate.cfg.xml:
<property name="current_session_context_class">thread</property>
<mapping resource="com/v512/examples/Guestbook.hbm.xml" />
<event type="post-update">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-insert">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-delete">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-collection-recreate">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-collection-remove">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-collection-update">
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
my lib version:
Quote:
hibernate core:3.3.2 GA
hibernate search:3.1.1 GA
who knows reason? thanks.