title: Error in a ManyToMany Relationship on Hibernate-JPA
body: <p>I have a large DB on MySql Workbench and I'm trying to map the relationship between the entities on Eclipse Mars thanks to Hibernate and the JPA module. The fact is that I receive the error:
  "In attribute 'personAddresses', the "mapped by" attribute 'peopleAdd' has an invalid mapping type for this relationship."
  This are the entities involved.</p>
  
  <p><a href="http://i.stack.imgur.com/S0nz4.png" rel="nofollow">1</a></p>
  
  <p>I've to say that making a forward engineering, Hibernate creating for me an AddressId class, where the composite primary key of Address is mapped. I suspect that the problem could be this, but I'm not certain, can you help me please?
  Under I post the code so that it's more clear to understand how the classes are implemented.</p>
  
  <pre><code>@Entity
  @IdClass(AddressId.class)
  @Table(schema = "YouDroop", name = "Address")
  public class Address implements Serializable
  {
  ...
  
  private Collection&lt;Person&gt; peopleAdd = new HashSet&lt;Person&gt;();
  
  @Id
  @Column(name = "Address", length = 45, unique = true, nullable = false)
  private String address;
  @Id
  @Column(name = "Number", unique = true, nullable = false)
  private int number;
  
  ...
  
  @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
  @JoinTable(
             name = "PersonHasAddress",
             joinColumns = {
                             @JoinColumn(name = "Address_Address", referencedColumnName = "Address", nullable = false),
                             @JoinColumn(name = "Address_Number", referencedColumnName = "Number", nullable = false)
                             },
             inverseJoinColumns = {@JoinColumn(name = "Person_Email", referencedColumnName = "Email", nullable = false)}
             )
  public Collection&lt;Person&gt; getPeopleAddressed(){
      return this.peopleAdd;
  }
  
  public void setPeopleAddressed(Collection&lt;Person&gt; people){
      this.peopleAdd = people;
  }
  }
  
  public class AddressId implements Serializable
  {
  
  private String address;
  private int number;
  
  public AddressId(){}
  
  public AddressId(String address, int number) {
      super();
      this.address = address;
      this.number = number;
  }
  
  ...
  }
  
  @Entity
  @Table(name = "Person", schema = "YouDroop", uniqueConstraints =
  { @UniqueConstraint(columnNames = "NickName"),
  @UniqueConstraint(columnNames = "Password") })
  public class Person implements Serializable
  {
  ...
  
  private Collection&lt;Address&gt; addresses = new HashSet&lt;Address&gt;();
  
  ...
  
  @ManyToMany(fetch = FetchType.LAZY, mappedBy = "peopleAdd")
  public Collection&lt;Address&gt; getPersonAddresses(){
      return this.addresses;
  }
  
  public void setPersonAddresses(Collection&lt;Address&gt; addresses){
      this.addresses = addresses;
  }
  }
  </code></pre>