title: Hibernate: Mapping User-Friends relation in Social Networks
body: <p>It's quite some time that I'm trying to figure out this problem and from googling around many people have similar problems.</p>
  
  <p>I'm trying to model a User in a Social Network, using Hibernate, and what is more basic to a social network than to map a friendship relation?
  Every user in the system should have a list of it's friends and I thought that this might be an incredibly easy task (just use a ManyToMany relation, right?). So I went on to try the following:</p>
  
  <pre><code>@Entity
  @Table(name="users")
  public class User {
     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     @Column(name="userid")
     protected Long id = null;
     @ManyToMany
     protected List&lt;User&gt; friends = null
  }
  </code></pre>
  
  <p>The problem now is that it tells me I use ManyToMany wrongly by having no clear distinction between friend and befriended. So far so good, I get the error, but how can I do what I want?</p>
  
  <p>Any idea? I've reached the end of my wisdom.</p>