@IndexedEmbedded in the list of lazily loaded objects, does not fall into the search index automatically

I have a problem that I think should be easily resolved.

I use Hibernate Search to index @Entitiy classes that are related to other objects.

Whenever an entity points to another object that also needs to be indexed, say the User who uploaded a particular photo, I use @IndexedEmbedded, which worked fine with HSearch auto indexing.

However, I also have @IndexedEmbeded annotations defined for @ManyToOne relationships. Imagine a photo with a list of related comments. These are loaded by default with lazy loading, i.e. They are not retrieved from the database until they are needed. I noticed that when I add a comment, no matter how much time has passed, it is not indexed until I manually reindex. Then everything works fine. I have not observed this with any of the other IndexedEmbedded relationships that I have, for example, if I change the location of the photo, after a few minutes it falls into the index and is perfectly visible.

Any explanation? Decision?

+4
source share
2 answers

I think this problem with @IndexEmbedded was flagged as an error. See this bug report and revised version.

If the version you are using is older, this may solve your problem.

0
source

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-directional relationship (using mappedBy) and the use of @ContainedIn. This is pretty much I think you need your example to work.

0
source

Source: https://habr.com/ru/post/1433959/


All Articles