Hi,
I have the following setup
Code:
@OneToMany(cascade={ CascadeType.ALL },orphanRemoval=true,mappedBy="post",fetch=FetchType.LAZY)
@BatchSize(size = 10)
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE,region=CacheRegion.WALL)
@Field(name="placeholder")
@FieldBridge(impl=CommentFieldBridge.class)
@OrderBy
public Set<Comment> getComments() {
return comments;
}
This fieldbridge is responsible for indexing the last element in the Set of comments with the Post.
Code:
public class CommentFieldBridge implements FieldBridge{
@Override
public void set(String name, Object value, Document document, LuceneOptions options) {
Set<Comment> comments = (Set<Comment>) value;
}
First a few observations:
1. All the comments are being loaded in the field bridge, regardless of the setting BatchSize. It would make more sense to me to preload the @BatchSize and load the rest on demand. I'm wondering: what if there are 10.000 comments? I'm also wondering if this behaviour (loading all children when a new child is added) is normal or caused by the use of the FieldBridge?
Then the question: how to best implement this in a way that is performant and scalable? Obviously, loading all comments by default in the Fieldbridge is neither.
* I was thinking of adding an extra field to the Post class.
Code:
Set<Comment> Comments = new HashSet<Comment>();
Comment lastComment;
public void addComments(Comment comment){
comments.add(comment);
lastComment = comment;
}
@ManyToOne
public Comment getLastComment(){
return lastComment;
}
* I'm not too sure what would be the best setting for cascading with a combination of a @ManyToOne and a @OneToMany that point to the same object.
Any suggestions?
Kind regards,
Marc