-->
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.  [ 2 posts ] 
Author Message
 Post subject: Automatic indexing fails
PostPosted: Tue May 12, 2009 5:12 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I have an issue with automatic indexing failing. It seems to be related to the use of transactions. I use Spring 2.5.6, Hibernate 3.3.1 and Hibernate Search 3.1.0 with annotations.

My transaction setup applies transaction automatically at the service level like so.
Code:
Applicationcontext-service.xml
    <aop:config>
        <aop:advisor id="userManagerTx" advice-ref="userManagerTxAdvice" pointcut="execution(* *..service.UserManager.*(..))" order="0"/>       
        <aop:advisor id="userManagerSecurity" advice-ref="userSecurityAdvice" pointcut="execution(* *..service.UserManager.saveUser(..))" order="1"/>
        <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Manager.*(..))" order="2"/>
    </aop:config>

persistence.xml
         <property name="hibernate.search.default.directory_provider"
            value="org.hibernate.search.store.FSDirectoryProvider" />
         <property name="hibernate.bytecode.provider"
            value="javaassist" />
         <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/indexes" />
         <property name="hibernate.search.autoregister_listeners" value="true"/>


Offer is a class I'm trying to index with child classes saved as joined subclasses
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 IOffer, 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;
   }

etc

}



In the following cases, when I save an object, the index is not automatically updated. Nor is it updated if I explicitly index the object.

Code:
**DAO**
Offer off = super.save(offer);
return off;

**DAO**
      Offer off = super.save(offer);
      FullTextSession fts = Search.getFullTextSession(this
            .getSessionFactory().getCurrentSession());

      if (offer.isActive() || offer.isValid()) {
         fts.index(off);
      } else {
         fts.purge(Offer.class, offer.getId());
      }
      return off;


In the following case it is indexed properly.
Code:
      Offer off = super.save(offer);
      FullTextSession fts = Search.getFullTextSession(this
            .getSessionFactory().getCurrentSession());
      Transaction tx = fts.beginTransaction();

      if (offer.isActive() || offer.isValid()) {
         fts.index(off);
      } else {
         fts.purge(Offer.class, offer.getId());
      }
      tx.commit();
      return off;


The difference being the explicit transaction demarcation. Now, I would expect an successful update based on the first case, since we are talking automatic indexing here.

Code:
Offer off = super.save(offer);
return off;


Any idea what I might be doing wrong?

Kind regards,

Marc
Kind regards,

Marc


Top
 Profile  
 
 Post subject: Re: Automatic indexing fails
PostPosted: Thu May 14, 2009 6:21 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

transaction problems when using Spring is a quite common problem. There are several threads regarding this issue on this forum. However, in most cases people choose to use declarative transaction management via the @Transactional annotation.

In your case the question is really how your txAdvice is implemented and which transaction manager it is using. Also how are your transactions propagated? Sometimes it helps to turn on some logging (especially transaction logging).

I recommend you go through the AOP and Transaction documentation of Spring to get a deeper understanding on these topics.

--Hardy


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