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.