-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to trigger the index when i update the secondary table
PostPosted: Fri Dec 28, 2007 9:29 am 
Newbie

Joined: Fri Dec 28, 2007 7:38 am
Posts: 16
Hi,

this my Entity bean classes are
Code:
@Indexed
public class TblAuthor implements Serializable
{
   @Id
   @DocumentId
   private long authorid;

   @Field(index=Index.TOKENIZED)
   private String authorname;

@OneToMany
@IndexedEmbedded
private Set<TblBook> bookCollection;
   
}


@Indexed
public class TblBook implements Serializable
{
   @Id
   @DocumentId
   private long bookid;

   @Field(index=Index.TOKENIZED)
   private String bookname;

@ManyToOne
private TblAuthor author;
   
}

persistence.xml
Code:
<!-- use a file system based index -->
       <property name="hibernate.search.default.directory_provider"
            value="org.hibernate.search.store.FSDirectoryProvider"/>
       <!-- directory where the indexes will be stored -->
       <property name="hibernate.search.default.indexBase"
            value="/shoppingindia_index"/>
      
       <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"/>

Session bean class is
Code:
public class SearhAction implements Search,Serializable
{
@PersistenceContext(type=PersistenceContextType.EXTENDED)
   private EntityManager em;

   String queryString;

@Out(required=false)
List<TblAuthor> resultList;

   public void doSearch ()
{
      Map<String,Float> boostPerField = new HashMap<String,Float>();
         boostPerField.put("authorname ", 4f);                   
         boostPerField.put("bookCollection. bookname", 4f);
         String[] productFields = {" authorname"bookCollection. bookname"};
         QueryParser parser = new MultiFieldQueryParser(productFields, new StandardAnalyzer(), boostPerField);
         parser.setAllowLeadingWildcard(true);          
         luceneQuery = parser.parse(queryString);
   resultList=((FullTextEntityManager)em).createFullTextQuery(luceneQuery,TblAuthor.class).getResultList();
}

}


the seach function is working fine.
After update the primart table
Quote:
TblAuthor
index is triggerd.
but
i have issue when i update the seconday table value
Quote:
TblBook

the index is not triggered properly

i dont know how to resolve this problem
any help ...

By
Thiagu.m


Top
 Profile  
 
 Post subject: Re: How to trigger the index when i update the secondary tab
PostPosted: Fri Dec 28, 2007 11:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you tried to add @ContainedIn to
Code:
@ManyToOne
private TblAuthor author;


in TblBook.

From the Hibernate Search documentation http://www.hibernate.org/hib_docs/search/reference/en/html_single/#d0e1218:
Quote:
When @IndexedEmbedded points to an entity, the association has to be directional and the other side has to be annotated @ContainedIn (as see in the previous example). If not, Hibernate Search has no way to update the root index when the associated entity is updated (in ou example, a Place index document has to be updated when the associated Address instance is updated.


By the way, depending on whether you really want to search in the TblBook index you might or might not need the @Indexed annotation in TblBook.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 29, 2007 2:13 am 
Newbie

Joined: Fri Dec 28, 2007 7:38 am
Posts: 16
thank u mr hardy.ferentschik
yor reply is very useful to me

by
thiagu.m


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