-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Thu Apr 01, 2010 10:09 am 
Newbie

Joined: Thu Apr 01, 2010 9:47 am
Posts: 6
I'm having trouble getting Hibernate Search to automatically update the Lucene index for entities which are @ContainedIn an entity, which is again @ContainedIn another entity.
The class structure in question is as follows: There are HelpItems and Tags, which are linked many-to-many via another entity HelpItemTag. The HelpItem is the only @Indexed entity, it embeds all tags via @IndexedEmbedded. In code:

Code:
@Entity()
@Indexed
public class HelpItem
{

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "helpItem")
   @IndexedEmbedded
   private List<HelpItemTag> tags;
}

@Entity()
public class HelpItemTag
{
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "helpItem", nullable = false)
   @ContainedIn
   private HelpItem helpItem;

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "tag", nullable = false)
   @IndexedEmbedded
   private Tag tag;
}

@Entity()
public class Tag
{

   @Column(nullable = false, length = 50)
   @Field(index = org.hibernate.search.annotations.Index.TOKENIZED, store = Store.NO)
   @Boost(1.5f)
   private String name;

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "tag")
   @ContainedIn
   private List<HelpItemTag> helpItems;
}


It almost works perfectly: tag names are flattened and indexed as part of the HelpItem Lucene index as expected. When adding or removing a HelpItemTag, the Lucene index is automatically updated as well. However, when a Tag changes name, this is NOT propagated to the HelpItem index, even though the relationship with HelpItemTag is bidirectional and annotated with @ContainedIn.

Am I doing something wrong or is this way of working not possible with Hibernate Search? In the mean time I'm using a workaround: manually triggering a reindex of all connected HelpItems whenever a Tag changes, but it would be nice if this could be automated in some way.


Top
 Profile  
 
 Post subject: Re: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Thu Apr 01, 2010 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
This is supposed to work.
could you try marking HelpItemTag also as @Indexed ? I know it's not a clean solution but would help me to understand.

you're not seeing any warning during Session startup about some wrong mapping?

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


Top
 Profile  
 
 Post subject: Re: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Fri Apr 02, 2010 4:09 am 
Newbie

Joined: Thu Apr 01, 2010 9:47 am
Posts: 6
Marking HelpItemTag with @Indexed does not make any difference, unfortunately. For good measure I also tried marking Tag with it, which also had no effect on this problem.
There are no warnings about wrong mappings (or other warnings) either.

Could this be a caching issue somehow? All my entities are also annotated with @Cache, which caused a different, unrelated problem earlier: when deleting a HelpItemTag, the lazy reference to it inside Tag would not get cleared, resulting in a lazy init exception once you tried loading the Tag and its references. I ended up refreshing the Tag object when deleting a HelpItemTag, which solved this. I don't really think it's related though, since I can reproduce the indexing problem without messing with any HelpItemTags.


Top
 Profile  
 
 Post subject: Re: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Fri Apr 02, 2010 4:34 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
could you create a test and attach it to JIRA?
thanks

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


Top
 Profile  
 
 Post subject: Re: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Fri Apr 02, 2010 10:52 am 
Newbie

Joined: Thu Apr 01, 2010 9:47 am
Posts: 6
Hi,
I've created a testcase that demonstrates the issue and reported it at http://opensource.atlassian.com/project ... SEARCH-488 .


Top
 Profile  
 
 Post subject: Re: Hibernate Search: nested / transitive use of @ContainedIn
PostPosted: Fri Apr 02, 2010 11:19 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
cool, thanks

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


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