Hibernate annotation to a transient collection field
I would like a collection field to use a query, but I cannot find a way to
do it. There is a @Formula annotation, but that doesn't work with
collections. You might ask why I just don't use @ManyToMany or similar
annotation. The thing is, I have a table (say, called Relationships) with
columns similar to this:
ID | ChildType | ChildID | ParentType | ParentID |
Now, the ChildType and ParentType can be one of many classes in my
application, therefore I cannot (I don't want to) use @ManyToMany mapping,
since it will create another table for each class. What I would like is,
to have a collection field called relationships in, say, class A, that
would select all rows (relationships) from Relationship table, where
ChildID = A.id and ChildType = 'A'. Is that possible?
 
No comments:
Post a Comment