Wednesday 15 January 2014

hibernate - Many-to-many on the same table with additional columns -


I have a class user A user can have a friend with many other users The relationship is mutual if A Friends are friends of the BA. I also want every relation to store additional data - for example, when two users become friends, so there are many relationships on the same table with this extra column. I know that a middle class friendship should be created (two user IDs and columns for date). But I'm coming down on this mapping with hibernation. What stops me is that mapping is in the same table. I can solve it, if there were many-to-many relationships between two different tables.

You said that

many-to-many relationships On the same table

This is not a good idea. There is a nightmare to maintain it.

@Antity Public Sector Friend {@Id @ generatedValue (strategy = GenerationType.AUTO) Private Integer Friend Idi; Name of the @column private string; @OneToMany (mapped = "me") private list & lt; MyFriends & gt; My friends; } @Entity Public Class MyFriends {@EmbeddedId Personal MyFriends Id; @column private string extra column; @ManyToOne @JoinColumn (name = "ME_ID", insertable = false, updateable = false) Private friend me; @ManyToOne @JoinColumn (name = "MY_FRIEND_ID", insertable = false, updateable = false) Personal Friend myFriend; @ Embedded public static class MyFriendsId serializable {@ column (name = "ME_ID", NABEL = incorrect, updateable = false) applies personal integer iid; @ Column (name = "MY_FRIEND_ID", nullable = false, updateable = false) private integer myFriendId; Public Boolean equivalent (object o) {If (o == empty) false return; If (! (MyFriendsI's example) false return; MyFriendsId other = (MyFriendsId); if (! (Forgot other.) Will get back (getMeId ()); if (! (Other.metafreeend id.) Equal (getMyFriendId () Returned false; Return;} Public int ishosh () {// hash code encrypt}}}

is concerned,


No comments:

Post a Comment