I m trying to implement a application. In this application i have an entity name comment,answer,question. Question,answer and comment has comments so i m planning to create a Commentable class and all of three class can extend Commentable. In this commentable class it hold Set but i wonder this structure's performance. Because it will always create a join query to get comments. What if i create a seperate comment entity which has commentedObjectId and when comments are needed make query on seperate table like where commentedObjectId = id ?
class Answer extends Commentable{}
class Comment extends Commentable{}
class Question extends Commentable{}
class Commentable extends BaseModel{
@OneToMany
Set<Comment> comments;
public Set<Comments> getComments() {
return comments;
}
public void setComments(Set<Comment> comments) {
this.comments = comments;
}`
alternative for avoiding join operations. Should i denormalize database like that?
class Comment extends BaseModel {
String commentedObjectId;
public String getcommentedObjectId() {
return commentedObjectId;
}
public void setcommentedObjectId(String commentedObjectId) {
this.commentedObjectId = commentedObjectId;
}
}