-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Search - Indexing newly created objects
PostPosted: Fri Jul 18, 2008 4:08 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.2 ga

Mapping documents:

Class annotated for search:

@Indexed(index="contacts")
public class Contact extends AbstractBusinessObject {
@Override
@DocumentId
public int getId() {
return super.getId();
}

@Field(name="firstName", index=Index.TOKENIZED, store=Store.YES)
public String getFirstName() {
return firstName;
}
}

In hibernate.cfg.xml:

<hibernate-configuration>
<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>
</session-factory>
</hibernate-configuration>

I use an hbm for the contact class, not annotations. I use spring and also tried adding the event listeners to my LocalSessionFactory config.

<!-- hibernate search -->
<property name="eventListeners">
<map>
<entry key="post-update">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
<entry key="post-insert">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
<entry key="post-delete">
<bean class="org.hibernate.search.event.FullTextIndexEventListener"/>
</entry>
</map>
</property>

If this seems correct and more of a spring-related issue, let me know and I'll change forums. Seems like things partially work though....so perhaps someone can steer me in the right direction.

Name and version of the database you are using: MySQL 5.0.22

I have successfully done a manual index on a list of contacts and can search for them successfully. Once an object is indexed, updates to the object seem to be reflected in the index. However, when a new object is created it never gets indexed.

I though that adding the hibernate config would allow all hibernate-managed objects that are search annotated to get indexed on the above events...what am I missing?


Top
 Profile  
 
 Post subject: Forgot to specify the version of hibernate search
PostPosted: Fri Jul 18, 2008 4:11 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
hibernate-search 3.0.0.GA as a maven dep, which fetched:
- hibernate-commons-annotations-3.0.0.ga.jar
- lucene-core-2.2.0.jar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 18, 2008 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this should work just fine if really events are configured.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 18, 2008 6:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
though, I'm not sure why you don't use Hibernate Search 3.0.1

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Any ideas...?
PostPosted: Fri Jul 18, 2008 6:54 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
I am not using 3.0.1 because I was using maven to fetch my deps and 3.0.0.ga is the latest. I can try 3.0.1 if you thing there may be an issue with 3.0.0?

Assuming 3.0.0 isn't broken when it comes to post-insert events, can you think of anything else I should try? I have it configured as mentioned. I take it you don't see anything out of place in my config.

Perhaps there is a sample project setup with hibernate search that I can pick apart and compare my own configuration with...


Top
 Profile  
 
 Post subject: Verified correct event configuration, same problem
PostPosted: Mon Jul 21, 2008 4:38 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
I recompiled hibernate-search with some additional debugging:

public void onPostInsert(PostInsertEvent event) {
System.err.println("onInsert called");
if (used) {
System.err.println("used!");
final Object entity = event.getEntity();
DocumentBuilder<Object> builder = searchFactoryImplementor.getDocumentBuilders().get( entity.getClass() );
//not strictly necessary but a smal optimization
if ( builder != null ) {
Serializable id = event.getId();
processWork( entity, id, WorkType.ADD, event );
}
} else {
System.err.println("not used!");
}
}

private void processWork(Object entity, Serializable id, WorkType workType, AbstractEvent event) {
System.err.println("processing work");
Work work = new Work(entity, id, workType);
searchFactoryImplementor.getWorker().performWork( work, event.getSession() );
}


I verified that on create of a new object, it entered the correct method of the event handler and entered the IF check and gets to processWork. However, the newly created object never ends up in the index from what I can tell.

BTW, I am able to see that the changes show up when searching on an unchanged field of an object after an update, but I can't search on the new value. Also when I open up the indexes with Luke I never see the updates in the lucene index at all.

Perhaps these issues are all related? Is there perhaps something special I need to do (like a special TX commit) to get these changes to make it into the indexes? Right now I have my dao's accessed through managers wrapped using the spring TransactionProxyFactory bean, so I do have a transaction being created and commited on these creates/updates.


Top
 Profile  
 
 Post subject: Another topic shed some light on this...bug or feature?
PostPosted: Mon Jul 21, 2008 4:55 pm 
Newbie

Joined: Tue Aug 02, 2005 4:53 pm
Posts: 14
http://forum.hibernate.org/viewtopic.ph ... 94#2390894


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.