-->
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.  [ 4 posts ] 
Author Message
 Post subject: Automatic index not created on save
PostPosted: Mon Dec 22, 2008 10:02 pm 
Newbie

Joined: Mon Dec 22, 2008 9:50 pm
Posts: 3
Hi,

I have an appfuse based project with Hibernate 3.2.6., entitymanager 3.3.2, hibernate annotations 3.3.1, hibernate search 3.0.1, Spring 2.5.4

I have a problem with one of my entities not being indexed automatically. However, when I run an explicit index operation using createFullTextSession and indexing all the objects, it does get indexed.

I dont have access to the sessionFactory in xml, but I do to the persistence.xml, which is configured as follows

Code:
   <persistence-unit name="ApplicationEntityManager"
      transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.search.default.directory_provider"
            value="org.hibernate.search.store.FSDirectoryProvider" />
         <property name="hibernate.search.autoregister_listeners"
            value="true" />
         <property name="hibernate.search.default.batch.merge_factor" value="1"/>
         <property name="hibernate.search.default.indexBase"
            value="d:/Java/Projects/CompraVenta/indexes" />
            
         <property name="hibernate.ejb.event.post-insert"
                value="org.hibernate.search.event.FullTextIndexEventListener"/>
         <property name="hibernate.ejb.event.post-update"
                value="org.hibernate.search.event.FullTextIndexEventListener"/>
         <property name="hibernate.ejb.event.post-delete"
                value="org.hibernate.search.event.FullTextIndexEventListener"/>
      </properties>
   </persistence-unit>



Some of my classes do get indexed automatically properly but one doesn't and I don't get it

It is this class

Code:
@Entity
@Table(name = "Offers")
@Inheritance(strategy = InheritanceType.JOINED)
//@DiscriminatorValue(value = "OFFER")
@Indexed
@FullTextFilterDefs( {
        @FullTextFilterDef(name = "offerTerms", impl = OfferFilterFactory.class),
        @FullTextFilterDef(name = "validUntil", impl = RangeFilterFactory.class) })
public class Offer implements Serializable{
[...]
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "offerID", updatable = false, insertable = false)
   @DocumentId
   public Long getId() {
      return id;
   }

   @Column
   @Field(index = Index.TOKENIZED, store = Store.YES)
   public String getTitle() {
      return title;
   }

   @Column
   @Field(index = Index.TOKENIZED, store = Store.YES)
   @Boost(2.5f)
   public String getDescription() {
      return description;
   }

[...]
}


the save operation is as follows:

Code:
    @SuppressWarnings("unchecked")
    public T save(T object) {
        return (T) super.getHibernateTemplate().merge(object);
    }

leading to

   public Object merge(final Object entity) throws DataAccessException {
      return executeWithNativeSession(new HibernateCallback() {
         public Object doInHibernate(Session session) throws HibernateException {
            checkWriteOperationAllowed(session);
            return session.merge(entity);
         }
      });
   }




Any ideas?

Cheers,

Marc[/code]


Top
 Profile  
 
 Post subject: Solved
PostPosted: Sat Dec 27, 2008 10:19 am 
Newbie

Joined: Mon Dec 22, 2008 9:50 pm
Posts: 3
Turns out to be a simple configuration issue:
I had added to persistence.xml but should have added the following to hibernate.cfg.xml

Code:
   <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>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 27, 2008 10:01 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, don't forget the collection listeners too:

Code:
<event type="post-collection-recreate">
   <listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>
<event type="post-collection-remove">
   <listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>
<event type="post-collection-update">
   <listener class="org.hibernate.search.event.FullTextIndexCollectionEventListener"/>
</event>


Did you solve the problem? the solution is quite disappointing for some reasons:
1)why didn't the configuration work automatically (the versions you use should be able to self-register)
2)why didn't it behave the same way for all entities?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Actually no
PostPosted: Sun Dec 28, 2008 10:03 am 
Newbie

Joined: Mon Dec 22, 2008 9:50 pm
Posts: 3
Hi,

Actually, it did not solve my problem. I thought it did, but it turns out that I was looking at a collection created manually from a batch indexing operation and I hadnt checked the dates.

I'm still looking at it with a "I dont get this" look on my face.

The automatic indexing works for another class but not for this particular one.

Cheers,

Marc


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