title: Java Persistence api: class uses non-entity class as target entity in the relationship attribute
body: <p>Good day. I try to have many-to-many dependencies with persistence api.
  I fill an new user data and try to add it to the database, but get an exception:</p>
  
  <p><code>Exception Description: [class main.java.entities.User] uses a non-entity [class main.java.entities.UserAccounts] as target entity in the relationship attribute [field accounts].</code></p>
  
  <p>I try to use difference values for @ManyToMany annotation in <code>name</code> section such as <code>bank_user_accounts</code> and <code>userAccounts</code>. Second value is a name of unit in <code>persistence.xml</code>. But this trouble still exists.</p>
  
  <p>User class:</p>
  
  <pre><code>@Entity(name="bank_users")
  public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
  
    @ManyToMany
    @JoinTable(
        name = "bank_user_accounts",
        joinColumns = @JoinColumn(name = "user_id"),
        inverseJoinColumns = @JoinColumn(name = "account_id")
    )
    private List&lt;UserAccounts&gt; accounts;
  }
  </code></pre>
  
  <p>UserAccounts class:</p>
  
  <pre><code>@Entity(name="bank_user_accounts")
  public class UserAccounts {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
  
    @Column(name = "user_id")
    private int userId;
  
    @Column(name = "account_id")
    private int accountId;
  }
  </code></pre>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"&gt;
    &lt;persistence-unit name="users" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;class&gt;main.java.entities.User&lt;/class&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
        &lt;property name="javax.persistence.jdbc.url" value="deleted" /&gt;
        &lt;property name="javax.persistence.jdbc.user" value="deleted" /&gt;
        &lt;property name="javax.persistence.jdbc.password" value="deleted" /&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  
    &lt;persistence-unit name="userAccounts" transaction-type="RESOURCE_LOCAL"&gt;
      &lt;class&gt;main.java.entities.UserAccounts&lt;/class&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /&gt;
        &lt;property name="javax.persistence.jdbc.url" value="deleted" /&gt;
        &lt;property name="javax.persistence.jdbc.user" value="deleted" /&gt;
        &lt;property name="javax.persistence.jdbc.password" value="deleted" /&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>