Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to model this strange, reflexive, self referencing relationship

phantasmoAug 1 2009 — edited Aug 3 2009
At first I though this was a design flaw on my end (as my [previous post|http://forums.sun.com/thread.jspa?threadID=5399766&tstart=15] shows), but now I'm pretty sure it's more complicated than that.

Here's the thing (simplified):

A user U1 has friends U2, U3 and U4, who are also users. This automatically means that users U2, U3 and U4 are friends with U1 (a reflexive relationship), and there are no additional rows mapping this. The join table, called FRIENDS, has an additional field - the date when the users became friends (so it looks like this: userId1, userId2, date).

Is it possible to model this in JPA so that the user entity has a list of friends? If yes, please try to explain how as this is mind boggling to me.

Is it maybe possible to modify the SQL for fetching relationship fields?

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 31 2009
Added on Aug 1 2009
6 comments
891 views