I have an issue, which I think should be easily solved.
I use Hibernate Search to index @Entitiy classes which have relations to other entities.
Whenever an entity points to another entity that should be indexed as well, say the User who uploaded a particular Photo, I use @IndexedEmbedded, which has worked absolutely fine with HSearch's automatic indexing.
However, I also have some @IndexedEmbeded annotations set on @ManyToOne relations. Imagine a photo having a list of related comments. These ones are by default lazily-loaded, i.e. not fetched from the DB, until actually needed. I noticed that when I add a comment, no matter how much time passes, it does not get indexed, until I do a manual reindexing. Then everything works fine. I have not observed this with any of the other IndexedEmbedded relations that i have, for instance, if I change the location of a photo, in a few minutes, it gets into the index and is perfectly searcheable.
Any explanation? Solution?
Your mapping should look something like this
@OneToMany(mappedBy="photo", cascade = { CascadeType.ALL}, fetch=FetchType.LAZY)
@IndexedEmbedded
@Type(type="java.util.Set")
private Set<Comment> comments;
...................................................
....................................................
@ContainedIn
@ManyToOne
@JoinColumn(name="PHOTO_ID")
private Photo photo;
Note the bi-directionality of relations (using mappedBy) and the use of @ContainedIn. This is pretty much I think you should need to make your example working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With