title: Use of @OneToMany or @ManyToMany targeting an unmapped class:
body: <p>So, hello stack overflow.
  I've trouble with hibrnate/jpa, got this exception: </p>
  
  <blockquote>
    <p>org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany
    targeting an unmapped class:
    com.vlad9pa.springapp.entity.User.roles[com.vlad9pa.springapp.entity.Role]</p>
  </blockquote>
  
  <p>I have 3 tables:</p>
  
  <ol>
  <li>users:id,username, password; </li>
  <li>roles:id, name; </li>
  <li>user_roles:user_id, roles_id.</li>
  </ol>
  
  <p>Import:</p>
  
  <pre><code>import javax.persistence.*;
  import java.util.Set;
  </code></pre>
  
  <p>Here is my entities and hibernate.cfg.xml:
  User:</p>
  
  <pre><code>@Entity
  @Table(name = "users")
  public class User {
  private int id;
  private String username;
  private String password;
  private Set&lt;Role&gt; roles;
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Basic
  @Column(name = "username")
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  @Basic
  @Column(name = "password")
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, targetEntity = Role.class)
  @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
          inverseJoinColumns = @JoinColumn(name = "role_id"))
  public Set&lt;Role&gt; getRoles() {
      return roles;
  }
  
  public void setRoles(Set&lt;Role&gt; roles) {
      this.roles = roles;
  }
  </code></pre>
  
  <p>Role:</p>
  
  <pre><code>@Entity
  @Table(name = "roles")
  public class Role {
  
  private int id;
  private String name;
  
  private Set&lt;User&gt; users;
  
  @Id
  @Column(name = "id")
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Basic
  @Column(name = "name")
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  
  
  @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "roles")
  public Set&lt;User&gt; getUsers() {
      return users;
  }
  
  public void setUsers(Set&lt;User&gt; users) {
      this.users = users;
  }
  </code></pre>
  
  <p>hibernate.cfg.xml:</p>
  
  <pre><code> &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQL9Dialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:postgresql://localhost:5432/e_shop&lt;/property&gt;
      &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
      &lt;property name="show_sql"&gt;false&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;mapping class="com.vlad9pa.springapp.entity.Role"/&gt;
      &lt;mapping class="com.vlad9pa.springapp.entity.User"/&gt;
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>