-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Hibernate Search] Lucene event listener not initialized
PostPosted: Wed Apr 25, 2007 10:40 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I'm French, so sorry for my english.

I try to use Hibernate Search, that's my code :

Code:
s = sessionFactory.openSession();
         
FullTextSession fullTextSession = Search.createFullTextSession(s);
         
QueryParser parser = new QueryParser("title", new StopAnalyzer() );

org.apache.lucene.search.Query luceneQuery = null;
try {
    luceneQuery = parser.parse( "nom:f" );
} catch (ParseException e) {
    e.printStackTrace();
}

org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery );

List result = (fullTextQuery).list(); //return a list of managed objects
Iterator i = result.iterator();
while(i.hasNext())
{
    System.out.println("bla : "+i.next());
}


And this is my error : Exception in thread "main" org.hibernate.HibernateException: Lucene event listener not initialized

I don't know what to do, could you help me ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi,
Which version are you using?
Are you using it with Hibernate Annotations?
Can you post your cfg.xml file?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 3:24 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I'm using Hibernate 3.2.

This is my cfg.xml :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/tablename</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.password">pass</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
       
        <property name="show_sql">true</property>
       
        <property name="hibernate.connection.autocommit">false</property>
       
        <!-- Use the C3P0 connection pool. -->
      <property name="c3p0.min_size">5</property>
      <property name="c3p0.max_size">20</property>
      <property name="c3p0.timeout">1800</property>
      
      <!-- Disable second-level cache. -->
      <property name="cache.provider_class">
         org.hibernate.cache.NoCacheProvider
      </property>
      <property name="cache.use_query_cache">false</property>
      <property name="cache.use_minimal_puts">false</property>
      <property name="max_fetch_depth">0</property>

      <property name="current_session_context_class">thread</property>
       
        <!-- Mapping objet/relationnel -->
        <mapping resource="com/demo/dao/config/Mapping.hbm.xml" />
       
    </session-factory>
</hibernate-configuration>


And if I'm using Annotations, I don't know, I put this in a class called "Categorie" :

Code:
import org.hibernate.search.annotations.*;

@Indexed(index="indexs/Categorie")
public class Categorie {

   private Integer id;

   private String nom;
   
   public Categorie() {}
   
   public Categorie(String nom)
   {
      this.nom = nom;
   }

   public String toString()
   {
      return(nom);
   }
   
   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }
   
   @Field(name="Abstract", index=Index.TOKENIZED, store=Store.YES)
   public String getNom() {
      return nom;
   }

   public void setNom(String nom) {
      this.nom = nom;
   }


I don't know where I must create an "indexs" Directory ?

Thank you.


Last edited by fabreax on Wed Aug 01, 2007 4:22 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 3:04 pm 
Newbie

Joined: Thu Apr 26, 2007 2:50 pm
Posts: 1
Location: St. Paul, MN
Add these hibernate listeners to the session factory:

<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>


Don't forget to add these hibernate properties:
<property name="hibernate.search.default.directory_provider">
org.hibernate.search.store.FSDirectoryProvider
</property>
<property name="hibernate.search.default.indexBase">
/usr/lucene
</property>

You will have to create the indexBase directory. Then, Hibernate Search will automatically create for you the indexs/Categorie directory inside /usr/lucene.

I used Hibernate Search 3.0.0 beta, Lucene 2.1.0 and Hibernate 3.2.2GA.

Make sure that you have the new notation for the hibernate properties, like instead of "cache.use_query_cache" you will have "hibernate.cache.use_query_cache".

It should work. Please take a look in the documentation, it is really small and easy to read.

Many many thanks to the Hibernate team that made Hibernate-Lucene integration so easy.

Lucian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 3:32 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Thank you very much for your answer. I already read the little Hibernate Search documentation but I don't understand all.

I change my cfg.xml file and I have this exception, I really don't understand what it means :S.


Last edited by fabreax on Wed Aug 01, 2007 4:34 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 4:12 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Up


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 01, 2007 3:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
be sure to use the latest hibernate core version witht he latest hibernate search version, check the compatibility matrix in the download page

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 3:01 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I use Hibernate 3.2.3 with Hibernate Search 3.0.0.Beta1 and lucene-core-2.1.0.

I don't know where is the problem :S


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 3:31 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I made a simple example.

This is my .cfg.xml file :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/testsfmn</property>
        <property name="hibernate.connection.username">fmn</property>
        <property name="hibernate.connection.password">mdp</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
       
        <!-- affiche les requetes sql crees par hibernate -->
        <property name="show_sql">true</property>
       
        <!-- commit automatique -->
        <property name="hibernate.connection.autocommit">false</property>
       
        <!-- Use the C3P0 connection pool. -->
      <property name="c3p0.min_size">5</property>
      <property name="c3p0.max_size">20</property>
      <property name="c3p0.timeout">1800</property>
      
      <!-- Disable second-level cache. -->
      <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <property name="cache.use_query_cache">false</property>
      <property name="cache.use_minimal_puts">false</property>
      <property name="max_fetch_depth">0</property>
      
      <!-- Enable Hibernate's automatic session context management -->
      <property name="current_session_context_class">thread</property>


      <!-- Hibernate Search -->
        <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property>
        <property name="hibernate.search.default.indexBase">/home/fmn/templucene</property>
       
        <!-- Mapping objet/relationnel -->
        <mapping resource="servicedonnees/Mapping.hbm.xml" />

        <!-- Hibernate Search auto indexing -->
      <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>

    </session-factory>

</hibernate-configuration>



My Mapping.hbm.xml could be empty or not, the error is the same.

This is a class which allows to get Sessions :
Code:
package servicedonnees;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class HibernateUtil
{
   private static final Configuration configuration;
   private static final SessionFactory sessionFactory;

   static
   {
      try
      {
         configuration = new Configuration();
         configuration.configure(); // hibernate.cfg.xml reading

         sessionFactory = configuration.buildSessionFactory();

      } catch (HibernateException e) {
         throw new RuntimeException("Probleme de configuration Hibernate : "+ e.getMessage(), e);
      }
   }

   public static final ThreadLocal<Session> session = new ThreadLocal<Session>();

   public static Session getSessionActuelle()
   {
      Session s = (Session) session.get();
      
      // open a new Session, if this Thread have none
      if (s == null)
      {
         s = sessionFactory.openSession();
         session.set(s);
      }
      return s;
   }

   public static void fermerSession()
   {
      Session s = (Session) session.get();
      session.set(null);
      if (s != null)
         s.close();
   }
   
   public static void reinitialiserDonnees()
   {
      SchemaExport se = new SchemaExport(configuration);
      se.create(true,true);
   }

   public static void main(String[] args)
   {
      // clear the database and insert tables
      HibernateUtil.reinitialiserDonnees();

      Session s = HibernateUtil.getSessionActuelle();
      
      
      FullTextSession fullTextSession = Search.createFullTextSession(s);
      
      QueryParser parser = new QueryParser("title", new StopAnalyzer() );

      org.apache.lucene.search.Query luceneQuery = null;
      try {
         luceneQuery = parser.parse( "nom:f" );
      } catch (ParseException e) {
         e.printStackTrace();
      }
      org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );

      List result = (fullTextQuery).list(); //return a list of managed objects
      Iterator i = result.iterator();
      while(i.hasNext())
      {
         System.out.println("bla : "+i.next());
      }

      // close the session
      HibernateUtil.fermerSession();
   }
}


The error appears at configuration.configure();

This is the error :
Code:
Exception in thread "main" java.lang.VerifyError: (class: org/hibernate/search/event/FullTextIndexEventListener, method: onPostInsert signature: (Lorg/hibernate/event/PostInsertEvent;)V) Incompatible argument to function
   at java.lang.Class.getDeclaredConstructors0(Native Method)
   at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
   at java.lang.Class.getConstructor0(Class.java:2671)
   at java.lang.Class.newInstance0(Class.java:321)
   at java.lang.Class.newInstance(Class.java:303)
   at org.hibernate.cfg.Configuration.setListeners(Configuration.java:1536)
   at org.hibernate.cfg.Configuration.parseEvent(Configuration.java:1521)
   at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1452)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
   at servicedonnees.HibernateUtil.<clinit>(HibernateUtil.java:34)



Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 03, 2007 9:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you have an old hibernate3.jar or hibernate-annotations.jar somewhere, most likely

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 8:00 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I haven't hibernate-annotations.jar, I have hibernate-commons-annotations.jar

I downloaded Hibernate Annotations and add hibernate-annotations.jar but the problem was still here.

Next, I tried to update hibernate.jar, it was that ! I have no errors.

Thank you very much !


Top
 Profile  
 
 Post subject: What if I'm using JPA and Annotations?
PostPosted: Wed Jul 18, 2007 6:39 pm 
Newbie

Joined: Wed Jul 18, 2007 6:35 pm
Posts: 8
A little late to the party, but....

I'm trying to add the event listeners to my config file but I use a persistence file that looks like this:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">

<persistence-unit name="Predict2">

<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>

<!-- DBMS Configuration -->
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost/predict"/>
<property name="hibernate.connection.username" value="predict"/>
<property name="hibernate.connection.password" value="predict"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<!-- END DBMS Config. -->

<property name="hibernate.c3p0.min_size"
value="5"/>
<property name="hibernate.c3p0.max_size"
value="20"/>
<property name="hibernate.c3p0.timeout"
value="300"/>
<property name="hibernate.c3p0.max_statements"
value="50"/>

<property name="hibernate.c3p0.idle_test_period"
value="3000"/>

<property name="hibernate.search.default.directory_provider"
value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase"
value="/usr/lucene" />

<!-- This property may be useful when doing tests since it drops and
re-creates the database schema when the persistence unit is created.
<property name="hibernate.hbm2ddl.auto" value="create"/>
-->
</properties>
</persistence-unit>

</persistence>


Where should I put the event handlers that are supposed to be in the sessionfactory tag?

Thanks,
K[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:33 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you use Hibernate EntityManager 3.3.x you don't need to declare the event listeners. They are autowired if HSearch is in the classpath

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 2:58 pm 
Newbie

Joined: Wed Jul 18, 2007 6:35 pm
Posts: 8
emmanuel wrote:
If you use Hibernate EntityManager 3.3.x you don't need to declare the event listeners. They are autowired if HSearch is in the classpath


Thanks. I updated a number of jars and seem to be beyond my previous error to a new one:

....
Not a mapped entity: class com.stottlerhenke.predict.service.persistence.Prediction
at org.hibernate.search.query.FullTextQueryImpl.buildSearcher(FullTextQueryImpl.java:323)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:209)
at com.stottlerhenke.predict.service.persistence.LuceneSearch.searchPredictions(LuceneSearch.java:79)
at com.stottlerhenke.predict.service.persistence.PredictPersistence.searchPredictions(PredictPersistence.java:266)
at com.stottlerhenke.predict.service.persistence.PredictPersistencePredictionTest.testSearchPredictions(PredictPersistencePredictionTest.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
.....

So this looks to me like my annotized classes are not being mapped in this full text session. I know they are without the Search capabilities though. Could it be that I'm missing some kind of initialization when I set up my FullTextSession? Here's my code for the Search part:


public class LuceneSearch
{

private static final String HIBERNATE_FILE = "META-INF/persistence.xml";

private QueryParser _parser;

private String[] _stopWords;

private FullTextSession _textSession;

private EntityManager _entityManager;

public LuceneSearch(EntityManager entityMgr)
{

_entityManager = entityMgr;
// Have to use sessions here
try
{
Session session = (Session) _entityManager.getDelegate();
_textSession = Search.createFullTextSession(session);
initialize(null);//use default stop words for now
}
catch (ClassCastException ce)
{
// this error supposedly should not get thrown as getDelegate()
// supposedly always returns a Session, but just in case.
// (this was from examples on the web and the #hibernate channel so
// needs to be verified
ce.printStackTrace();
// TODO: Wrap it up and do something else with it
throw ce;
}
}

private void initialize(String[] stopWords)
{
if (stopWords != null)
{
// first set up the parser with the new stop words
_parser = new QueryParser("text", new StandardAnalyzer(stopWords));

}
else
{// default stop words
_parser = new QueryParser("text", new StandardAnalyzer());
}
_stopWords = stopWords;
}

public List<Prediction> searchPredictions(String queryStr)
{
// look in text column of predictions
try
{
org.apache.lucene.search.Query luceneQuery = _parser.parse(queryStr);
Query query = _textSession.createFullTextQuery(luceneQuery,
Prediction.class);

return query.list();
}
catch (Exception pe)
{// KKG TODO: Turn this into a better exception
pe.printStackTrace();
}
return null;
}
}

Thanks again,
Kshanti


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It means that com.stottlerhenke.predict.service.persistence.Prediction is not part of your persistent unit.
Are you sure @java.persistence.Entity is defined in com.stottlerhenke.predict.service.persistence.Prediction?

Is it part of the jar containing your META-INF/persistence.xml?

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.