Tuesday, 15 May 2012

jpa - Hibernate many to many mapping the same entity -



jpa - Hibernate many to many mapping the same entity -

when mapping same entity answered here :

hibernate many-to-many association same entity

in "tbl_friends" table have rows same meaning. example, have user id=1 , user id=2. in "tbl_friends" table when linked friends have 2 rows

1-2 2-1

is posible somehow create kind of relationship in 1 row (1-2 or 2-1) using hibernate or jpa anotations?

no can't because 2 rows doesn't have same meaning. 1 row saying persona friend personb , other personb friend persona. functionnally speaking, in example, 2 relations might have same meaning that's not case @ database level (friendship not mutual ... that's sad). thing can hide in api :

public class person { private set<person> friends = new hashset<person>(); public void addfriend(person person) { friends.add(person); person.getfriends().add(this); } }

hibernate jpa many-to-many

No comments:

Post a Comment