Ok, say i have a "Friend" entity which needs to have "Friend"s as property Since this is a many to many connection, If i'd create this schema using SQL (Which i'm not, i'm using the hbm.ddl.auto to do it for me) i'd probably make another table containing 2 columns with 2 ids (1 for each friend) However, i'm not sure how to annotate this in hibernate, i did this:
class PersonEntity {
. .
@ElementCollection private List<PersonEntity> friends ;
. . }
Problem is, i'm not sure it's the best way.. for instance, i'm "thinking" that whenever i add a friend to the list and persist it will be inserted as the next row in the table, and since i can't seem to index this field i'm imagining the data retrieval will be inefficient. Can you suggest better ways to solve this problem?
|