title: Java Hibernate : org.hibernate.MappingException: Unknown entity
body: <p>i have a problem using hibernate with my java project and i hope that you can help me:</p>
  
  <p>First, here is some of my code: <br> The Entity class</p>
  
  <pre><code>package de.zaed.entities;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  
  @Entity
  @Table(name="USER")
  public class User {
  
  /**
   * the user id in the database
   */
  @Id
  private Long id; 
  
  /**
   * the username of a user
   */
  private String username;
  
  /**
   * the users password
   */
  private String password;
  
  /**
   * The role of a user
   */
  @OneToOne(mappedBy="user", cascade=CascadeType.ALL)
  private UserRole role;
  
  
  public Long getId() {
      return id;
  }
  
  public String getPassword() {
      return password;
  }
  
  public UserRole getRole() {
      return role;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public void setRole(UserRole role) {
      this.role = role;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }   
  }
  </code></pre>
  
  <p>the part where i add the class to the AnnotationConfiguration</p>
  
  <pre><code>config.addAnnotatedClass(User.class); 
  config.addAnnotatedClass(UserRole.class); 
  config.configure("hibernate.cfg.xml");
  </code></pre>
  
  <p>now my problem: <br>
  while executing the following code:</p>
  
  <pre><code>User dbUser = new User();
  dbUser.setUsername(username);
  dbUser.setPassword(password);
  
  Session session = DatabaseService.getSessionFactory().getCurrentSession();
  session.beginTransaction();
  
  session.save(dbUser);
  
  session.flush();
  
  session.close();
  </code></pre>
  
  <p>I get the  </p>
  
  <pre><code>org.hibernate.MappingException: Unknown entity: de.zaed.entities.User 
  </code></pre>
  
  <p>error while session.save(dbUser) is called.</p>
  
  <p>I've read many posts in forums and some tutorials but i could not find a fix for my problem.
  Hope you can help me.</p>
  
  <p>Thanks,
  kaQn4p</p>