-->
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.  [ 11 posts ] 
Author Message
 Post subject: lucene + ejb3 in standalone mode
PostPosted: Tue Oct 10, 2006 2:47 pm 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
Thanks for any idea who will help me to integrate lucene with ejb3 in standalone/embeded mode.

I don't know where to write this info, for automatic indexes:





Code:
<hibernate-configuration>
    ...
    <event type="post-commit-update"
        <listener 
            class="org.hibernate.lucene.event.LuceneEventListener"/>
    </event>
    <event type="post-commit-insert"
        <listener
            class="org.hibernate.lucene.event.LuceneEventListener"/>
    </event>
    <event type="post-commit-delete"
        <listener
            class="org.hibernate.lucene.event.LuceneEventListener"/>
    </event>
</hibernate-configuration>


thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 6:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi,
There are properties you can set up in the persistence.xml to override the event listeners through the hibernate.ejb.event.<eventtype> properties

Code:
hibernate.ejb.event.post-commit-update org.hibernate.lucene.event.LuceneEventListener
...


check
http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/#configuration

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 5:44 am 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
Hello,

thanks for your answer Emmanuel.

Still have problems with making lucene to work together with ejb3.

I created a new class who extends LuceneEventListener, to see when methods like onPostInsert,onPostUpdate,onPostDelete are called, and I register my class as listener (using persistence.xml file).



Code:
   public void onPostInsert(PostInsertEvent event) {
      super.onPostInsert(event);
      System.out.println("[PostInsertEvent] "+event.getEntity().getClass());
   }


insert event is not intercepted for my entity, defined in this way:

Code:
@Entity
@Indexed(index="index/test")
public class TestEntity {
...
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Keyword(id=true)
    public int getId () {
         return id;
    }
...
@Text(name="name")
   public String getName() {
      return name;
   }


Also I think automatic indexing don't work, because after inserting some records in TestEntity, I want to check if it's ok with
IndexSearcher is = new IndexSearcher("index/test");

I get FileNotFountException: index\test\segments

if I comment: @Indexed(index="index/test"), insert event is intercepted.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 8:30 am 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
what is wrong in my configuration?

1.why onPostInsert event is not intercepted for entity having @Indexed annotation?
2. segments file is not created ( I think because 1.)

I have this config in persistence.xml:


Code:
      <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="c:/index/"/>



and my entity is:
Code:
@Entity
@Indexed
//(index="test")
public class TestEntity {
   
   private String name;
   private int id;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Keyword(id=true)
    public int getId () {
         return id;
    }
     
    public void setId (int id) {
        this.id = id;
    }

   public void setName(String name) {
      this.name = name;
   }

   
   @Text
   public String getName() {
      return name;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 11:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
f I comment: @Indexed(index="index/test"), insert event is intercepted.

What do you mean exactly?
An entity wo @Indexed is actually indexed??

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 12:00 pm 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
Sorry for my english.

No, is not indexed if I comment @Indexed.

I want to say:
- it seems LuceneEventListener intercept onPostInsert event when my entity don't have @Indexed annotation.
- and don't intercept onPostInsert event if my enitity have @Indexed annotation


I read LuceneEventListener code and it seems fine. I talk about onPostInsert event because I saw this is the point where information is indexed, and if this event is not intercepted for an entity having @Indexed ... data will not be indexed by lucene.

something is wrong in my configuration? I just added info in persistece.xml, I added hibernate-lucene annotation in my entity + create output folder to keep lucene index.

thanks

ps.
I create records using Stateless session bean, EntityManager.permit(obj);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 12:52 pm 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
I mean EntityManager.persist(obj)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I suspect something is wrong with your overriding of LuceneEventListener
You System.out message should be displayed regardless of the fact that the actual even listener is working with the index or not. It is called for all entities.
The other explanation would be that the indexing code blow up during the indexing process but you should see an exception.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 4:25 pm 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
yes, you are right . Listener should be called for all entities and it is called also for indexed entities.

Now my code from listener looks like:

Code:
   public void onPostInsert(PostInsertEvent event) {
      System.out.println("[PostInsertEvent before] "+event.getEntity().getClass());
      super.onPostInsert(event);
      System.out.println("[PostInsertEvent after] "+event.getEntity().getClass());
   }


I see in my console only first System.out., something is wrong when index is created. Maybe this method should be synchronized to allow only one index to be added by lucene in a moment of time?

I don't see any exception. Also I don't see segments file created...

thanks a lot for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 11, 2006 7:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The event listener is synchronized when playing with the DirectoryProvider only.
Either you are swallowing an exception or your VM is stuck. If 2. do a thread dump to see where. If 1. don't swallow :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 10:45 am 
Newbie

Joined: Tue Oct 10, 2006 2:38 pm
Posts: 17
Thanks for your help Emmanuel

finally I solved my problem and I can see lucene+ejb3 in action.

I get latest files used by hibernate-lucene annotations and and all my problemes has gone.

many thanks for your help again
serj


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

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.