I have a polymorphic relationship represented by the interface commentable
. Comments can target posts as well as other comments.
I'm able to represent the comment side of that relationship, retrieving the target post, but I'm unable to represent the post side- e.g. I can't get the comments from the post.
I'm using @Any for polymorphism, but if that's not the correct way to do it, then I'll happily change directions.
If I just have the Comment code, things work fine
// Comment.java
@Any(
metaDef = "CommentableMetaDef",
metaColumn = @Column(name = "commentable_entity")
)
@JoinColumn(name = "commentable_id")
private Commentable target;
// Post.java
@OneToMany(mappedBy = "target", targetEntity = Comment.class)
private Set<Comment> comments;
^^ This breaks.
In case it's relevant, here's my metaDef
inside of a package-info.java
// package-info.java
@AnyMetaDef(name = "CommentableMetaDef", metaType = "string", idType = "int",
metaValues = {
@MetaValue(value = "COM", targetEntity = Comment.class),
@MetaValue(value = "POS", targetEntity = Post.class)
}
)
@AnyMetaDef(name = "ReactableMetaDef", metaType = "string", idType = "int",
metaValues = {
@MetaValue(value = "COM", targetEntity = Comment.class),
@MetaValue(value = "POS", targetEntity = Post.class)
}
)