-->
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: Diagnosing indexing problem
PostPosted: Sun Feb 01, 2009 4:28 pm 
Pro
Pro

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

I have a problem getting indexing to work, and I'm having a hard time diagnosing the reason. Automatic indexing fails. When I add a manual indexing action to the dao save action, I can trace to the point where the indexing work action is added to a post transaction queue.

However, the index doesn't get added. I'm wondering how to diagnose my problem. I'm thinking I have a configuration problem that doesn't throw an error

The class in question is a non abstract mother to child classes. I can see several Warnings during startup

Hibernate version:
Hibernate Search 3.1.0, Hibernate Core 3.3.1, Spring 2.5.6, Appfuse 2.0.2



WARN [main] DocumentBuilderContainedEntity.checkDocumentId(409) | @DocumentId specified on an entity which is not indexed by itself. Annotation gets ignored. Use @Field instead.


I have traced these to the child classes for the mother classes which have not been annotated for indexing.

My class looks like this:

@Entity
@Table(name = "Offers")
@Inheritance(strategy = InheritanceType.JOINED)
@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;
}

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

@ManyToOne(optional = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_PhotoID", nullable = true, updatable = true)
@IndexedEmbedded
public Photo getPhoto() {
return photo;
}

@Column
@Field(store = Store.YES, index = Index.TOKENIZED)
public Date getEntryDate() {
return entryDate;
}

@ManyToOne(optional = false, cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_CategoryID", nullable = true, updatable = true)
@IndexedEmbedded(depth = 2)
public Category getCategory() {
return category;
}

@OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_ValidityID",nullable=false,updatable=false)
@IndexedEmbedded
public Validity getValidity() {
return validity;
}

[...]

}



hibernate.cfg.xml


<hibernate-configuration>
<session-factory>
[...][class references]
<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>
<event type="post-collection-recreate" >
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-collection-remove" >
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>
<event type="post-collection-update" >
<listener class="org.hibernate.search.event.FullTextIndexEventListener" />
</event>

</session-factory>
</hibernate-configuration>

persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<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.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/xyz/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>
</persistence>



Any ideas?

Thanks,

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2009 10:24 am 
Hibernate Team
Hibernate Team

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

the annotations look ok - at least when it comes to the Offer class. The warning probably comes from the fact that one of the @IndexedEmbedded classes contains a @DocumentId even though the class itself is not indexed.

Is there anything else in the log file? How does your indexing code look like? Are you sure that your transaction management works properly. You are mentioning that you are using Spring. Are you using the HibernateTemplate or do you use declarative transaction management. I think it would help to see how the code between a transaction/session open and close looks like.

Some general comments. Since you are using annotations you don't need @DocumentId. @Id will automatically be selected as document id. You should also not have to register the event listeners explicitly. Neither in hibernate.cfg.xml nor in persistence.xml. hibernate.search.autoregister_listeners="true" is also the default and should not be needed.

Are the actual index directories actually created when you start the application?

--Hardy


Top
 Profile  
 
 Post subject: Response
PostPosted: Thu Feb 05, 2009 1:07 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi and thanks for your reply. To answer your questions:
I had removed all of indexEmbedded annotations. I personally think the warnings come from the child classes for the non-abstract Offer which don't have @DocumentId references.

The indexing code. I have tried the following:
Code:
Service:
@Service("offerManager")
@Transactional
public class OfferManagerImpl extends GenericManagerImpl<Offer, Long> implements
      OfferManager {
   public Offer save(Offer offer) {
[...]
      offer = offerDao.save(offer);
      return offer;
   }

DAO
public class GenericDaoHibernate<T, PK extends Serializable> extends HibernateDaoSupport implements GenericDao<T, PK> {
[...]
    @SuppressWarnings("unchecked")
    public T save(T object) {
        return (T) super.getHibernateTemplate().merge(object);
    }
}


@Repository("offerDao")
public class OfferDaoHibernate extends GenericDaoHibernate<Offer, Long> implements
        OfferDao {
[...]
   public Offer save(Offer offer) {
      Offer off = super.save(offer);
      FullTextSession fts = Search.getFullTextSession(this.getSessionFactory().getCurrentSession());
      fts.index(off);

      return off;
   }
}


I tried with and without fts.index(off). Autoindexing should not required the index action, right?

That's about it. I dont see anything special in the logs referring to this.
Yes, the index directories get created.

I will try to remove those event elements and the other suggestions you made.

I would appreciate a head's up if you see any issues in my code.

Thanks

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 10:23 am 
Hibernate Team
Hibernate Team

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

as far as I can see it should be ok. And you should need the explicit indexing. Are you saying it actually works when you are using the explicit indexing and it's not working without?

I have seen several post where the problem was the transaction support. You can configure your application to output spring transaction logging. This way you can see when a transaction gets created and commited. Are the changes properly persisted in the database?

You could also set the log4j category for [i]org.hibernate.search.backend.impl.lucene.works[i] to trace. You should then see something like 'add to Lucene index ...' when an entity gets indexed.

BTW, how do you know that indexing does not work? Do you run a query? Or do you use Luke to inspect the index?

--Hardy


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.