2 Replies Latest reply on Jun 30, 2006 7:07 AM by smenge

    Hibernate and Lucene: Where is the index?

    smenge

      Hi all,

      I think i got it running, but i dont find the actual index !

      I tried my self on a minimal example (the very first example of the Oreilly EJB3 Book:
      http://prdownloads.sourceforge.net/jboss/oreilly-ejb3-workbook_for_jboss404_GA.zip?download

      Then, I copied lucene-core-2.0.0.jar to "server/default/lib" .

      Then, I added these lines to persistence.xml

       <property name="hibernate.ejb.event.post-commit-update" value="org.hibernate.lucene.event.LuceneEventListener"/>
       <property name="hibernate.ejb.event.post-commit-insert" value="org.hibernate.lucene.event.LuceneEventListener"/>
       <property name="hibernate.ejb.event.post-commit-delete" value="org.hibernate.lucene.event.LuceneEventListener"/>
       <property name="hibernate.lucene.index_dir" value="/tmp/indexes"/>
      


      Then, I added the annotations to my domain class like this:
      @Entity
      @Indexed(index="cabinindex")
      @Table(name="CABIN")
      public class Cabin implements java.io.Serializable
      {
       private int id;
       private String name;
       private int deckLevel;
       private int shipId;
       private int bedCount;
      
       @Id
       @Column(name="ID")
       @Keyword(id=true)
       public int getId()
       {
       return id;
       }
       public void setId(int pk)
       {
       id = pk;
       }
      
       @Column(name="NAME")
       @Text(name="NAME")
       public String getName()
       {
       return name;
       }
       public void setName(String str)
       {
       name = str;
       }
      
      ...
      


      Everything compiled fine (of course i imported the corresponding package). Then created /tmp/indexes by hand. When deploying, server log says:

      17:10:14,619 INFO [LuceneEventListener] Setting index dir to /tmp/indexes
      17:10:14,620 INFO [LuceneEventListener] index: /tmp/indexes/cabinindex
      17:10:14,620 INFO [LuceneEventListener] Setting index dir to /tmp/indexes
      17:10:14,621 INFO [LuceneEventListener] index: /tmp/indexes/cabinindex
      17:10:14,621 INFO [LuceneEventListener] Setting index dir to /tmp/indexes
      17:10:14,622 INFO [LuceneEventListener] index: /tmp/indexes/cabinindex
      17:10:14,622 INFO [SessionFactoryImpl] building session factory
      17:10:14,641 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
      


      This tells me that the configuration seems to work.

      But (and heres my problem), when running the client, which persists a cabin, no index is appearing, no error messages, nothing. "/tmp/indexes" is empty.

      If i had an index, i would like to inspect it with "luke", but until now now success.

      Can anyone help me out with this? And: Has anyone got it running? I cant find anything helpful on the net on this topic ...

      TIA, Sebastian

        • 1. Re: Hibernate and Lucene: Where is the index?
          alesj

          Debug.

          See if the listener is actually called on persist - or in your case probably why not?

          Rgds, Ales

          • 2. Re: Hibernate and Lucene: Where is the index?
            smenge

            Could it be that the corresponding events arent fired, when persisting the entity from a simple client app outside the container?

            Further, i didnt find the events listed in the "integrate lucene with hibernate" docs in the docs of the entitymanager. compare these urls:

            http://docs.jboss.org/ejb3/app-server/HibernateEntityManager/reference/en/html_single/index.html#d0e488

            http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html#d0e2754

            package com.titan.clients;
            
            import com.titan.travelagent.TravelAgentRemote;
            import com.titan.domain.Cabin;
            
            import javax.naming.InitialContext;
            import javax.naming.Context;
            import javax.naming.NamingException;
            
            import javax.rmi.PortableRemoteObject;
            
            public class Client
            {
             public static void main(String [] args)
             {
             try
             {
             Context jndiContext = getInitialContext();
             Object ref = jndiContext.lookup("TravelAgentBean/remote");
             TravelAgentRemote dao = (TravelAgentRemote)ref;
            
             Cabin cabin_1 = new Cabin();
             cabin_1.setId(1);
             cabin_1.setName("Master Suite");
             cabin_1.setDeckLevel(1);
             cabin_1.setShipId(1);
             cabin_1.setBedCount(3);
            
             dao.createCabin(cabin_1);
            
             Cabin cabin_2 = dao.findCabin(1);
             System.out.println(cabin_2.getName());
             System.out.println(cabin_2.getDeckLevel());
             System.out.println(cabin_2.getShipId());
             System.out.println(cabin_2.getBedCount());
            
             }
             catch (javax.naming.NamingException ne)
             {
             ne.printStackTrace();
             }
             }
            
             public static Context getInitialContext()
             throws javax.naming.NamingException
             {
             return new javax.naming.InitialContext();
             }
            }