5

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?

Preslav Rachev
  • 3,983
  • 6
  • 39
  • 63
  • If you have a _Photo_ instance with a list of _Comment_s, then you really have a _@OneToMany_ association. It would help to see your actual entities. Also who is the owner of the association and is it a bidirectional association. If so, do you update both sides? And yes, which version of Search are you using? – Hardy Sep 19 '12 at 08:13

2 Answers2

1

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.

Shailendra
  • 8,874
  • 2
  • 28
  • 37
  • 1
    Tried it. Still, even after a significant amount of time, comments do not get to the indexes. – Preslav Rachev Sep 27 '12 at 14:12
  • Looks like it's time to dive into what's happening under the covers. Try enabling Hibernate search debug and see if you uncover something ! – Shailendra Sep 28 '12 at 07:29
0

I think this issue with @IndexEmbedded was reported as a bug. Please refer to this bug report and the fixed version.

If the version you are using is older then this might resolve your issue.

Shailendra
  • 8,874
  • 2
  • 28
  • 37