title: Hibernate ManyToMany same JoinColumn name
body: <p>I have two entity classes <code>Activity</code> and <code>User</code>. The relationships between them are:</p>
  
  <ul>
  <li>One <code>Activity</code> can have one or many <code>User</code></li>
  <li>One <code>User</code> can belongs to one or many <code>Activity</code></li>
  </ul>
  
  <p>So to achieve this I have defined <code>@ManyToMany</code> mapping between them. Below is my classes:</p>
  
  <p><code>Activity</code>:</p>
  
  <pre><code>@javax.persistence.Entity
  @Table(name = "ACTIVITY")
  public class Activity extends Entity {
  
      @Transient
      private static final long serialVersionUID = 4741665931936809028L;
  
      private Set&lt;User&gt; users;
  
      public Activity() {
          super();
      }
  
      @ManyToMany(targetEntity = User.class, cascade = { CascadeType.ALL })
      @JoinTable(name = "ACTIVITY_USER", joinColumns = @JoinColumn(name = "ID"), inverseJoinColumns = @JoinColumn(name = "ID"))
      public Set&lt;User&gt; getUsers() {
          return users;
      }
  
      public void setUsers(Set&lt;User&gt; users) {
          this.users = users;
      }
  }
  </code></pre>
  
  <p><code>User</code>:</p>
  
  <pre><code>@javax.persistence.Entity
  @Table(name = "USER")
  public class User extends Entity {
  
      @Transient
      private static final long serialVersionUID = -112950002831333869L;
  
      private Set&lt;Activity&gt; activities;
  
      public User() {
          super();
      }
  
      @ManyToMany(cascade = { CascadeType.ALL }, mappedBy = "users", targetEntity = Activity.class)
      public Set&lt;Activity&gt; getActivities() {
          return activities;
      }
  
      public void setActivities(Set&lt;Activity&gt; activities) {
          this.activities = activities;
      }
  }
  </code></pre>
  
  <p>Both of the above classes extends <code>Entity</code>:</p>
  
  <pre><code>@MappedSuperclass
  public class Entity implements Serializable {
  
      @Transient
      private static final long serialVersionUID = 7470288121057059283L;
  
      private Long id;
  
      public Entity() {
          super();
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "ID", updatable = false, nullable = false, unique = true)
      public Long getId() {
          return id;
      }
  
      @SuppressWarnings("unused")
      private void setId(Long id) {
          this.id = id;
      }
  
      public void setLastUpdateTimestamp(Date lastUpdateTimestamp) {
          this.lastUpdateTimestamp = lastUpdateTimestamp;
      }
  
  
      @Override
      public int hashCode() {
          final int prime = 31;
          int result = 1;
          return prime * result + ((getId() == null) ? super.hashCode() : getId().hashCode());
      }
  
      @Override
      public boolean equals(Object obj) {
          if (this == obj) {
              return true;
          }
  
          if (obj == null) {
              return false;
          }
  
          if (!getClass().equals(HibernateProxyHelper.getClassWithoutInitializingProxy(obj))) {
              return false;
          }
  
          final Entity other = (Entity) obj;
  
          if (getId() != other.getId()) {
              if (getId() == null) {
                  return false;
              }
              if (!getId().equals(other.getId())) {
                  return false;
              }
          }
  
          return true;
      }
  }
  </code></pre>
  
  <p>Now from: </p>
  
  <pre><code>@JoinTable(name = "ACTIVITY_USER", joinColumns = @JoinColumn(name = "ID"), inverseJoinColumns = @JoinColumn(name = "ID"))
  </code></pre>
  
  <p>what I understand that the name of the <code>@JoinColumn</code> of <code>joinColumns</code> takes the column name of the PK of one entity and the name of the <code>@JoinColumn</code> of <code>inverseJoinColumns</code> takes the column name of the PK of another entity. But in my case both of the column names are same, i.e., <code>ID</code> from the <code>Entity</code> class. </p>
  
  <p>My question is how can I avoid this confliction of the column names? Any suggestion would be very helpful to me.</p>