title: org.hibernate.MappingException: Unknown entity: Models.Users
body: <p><strong>I have viewed the related questions, but still don't find the answer to fix my error.</strong></p>
  
  <p>This is my project structure:</p>
  
  <pre><code> - src
    - java
     - HibernateDemo
       - HibernateTestApplication.java
       - HibernateUtil.java
     - Models
       - Users.java
     - res
       - hibernate.cfg.xml
       - Users.hbm.xml
  </code></pre>
  
  <p>This is my hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
  
      &lt;session-factory&gt;
  
          &lt;!-- Database connection settings --&gt;
          &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/test&lt;/property&gt;
          &lt;property name="connection.username"&gt;root&lt;/property&gt;
          &lt;property name="connection.password"&gt;***&lt;/property&gt;
  
          &lt;!-- SQL dialect --&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Enable Hibernate's automatic session context management --&gt;
          &lt;!--&lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;--&gt;
  
          &lt;!-- Disable the second-level cache  --&gt;
          &lt;!--&lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;--&gt;
  
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="format_sql"&gt;true&lt;/property&gt;
  
          &lt;!-- Drop and re-create the database schema on startup --&gt;
          &lt;!--&lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;--&gt;
  
          &lt;mapping resource="Users.hbm.xml"/&gt;
  
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>This is my Users.hbm.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD//EN"
      "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  
  &lt;hibernate-mapping&gt;
      &lt;class name="Models.Users" table="users"&gt;
          &lt;meta attribute="class-description"&gt;
              This class contains the users detail.
          &lt;/meta&gt;
          &lt;id name="id" type="int" column="id"&gt;
              &lt;generator class="native"/&gt;
          &lt;/id&gt;
          &lt;property name="name" column="name" type="string"/&gt;
          &lt;property name="age" column="age" type="int"/&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>This is my Users.java:</p>
  
  <pre><code>package Models;
  
  public class Users {
      private int id;
      private String name;
      private int age;
  
      public Users(){}
  
      public Users(String name, int age){
          this.name = name;
          this.age = age;
      }
  
      public int getId() {
          return id;
      }
  
      public String getName() {
          return name;
      }
  
      public int getAge() {
          return age;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public void setAge(int age) {
          this.age = age;
      }
  }
  </code></pre>
  
  <p>This is my HibernateUtil.java:</p>
  
  <pre><code>package HibernateDemo;
  
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.registry.StandardServiceRegistry;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  import java.io.File;
  
  public class HibernateUtil {
  
      private static HibernateUtil instance = null;
  
      private static SessionFactory sessionFactory;
      private static StandardServiceRegistry serviceRegistry;
  
      private HibernateUtil(){
          String hibernatePropsFilePath = "E:\\java workspace\\study\\hibernate\\src\\main\\java\\res\\hibernate.cfg.xml";
          File hibernatePropsFile = new File(hibernatePropsFilePath);
  
          Configuration configuration = new Configuration();
          configuration.configure(hibernatePropsFile);
          serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
          sessionFactory = configuration.buildSessionFactory(serviceRegistry);
      }
  
      public static HibernateUtil getInstance(){
          if(instance == null){
              instance  = new HibernateUtil();
          }
          return instance;
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
  }
  </code></pre>
  
  <p>This is my HibernateTestApplication.java:</p>
  
  <pre><code>package HibernateDemo;
  
  import Models.Users;
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.Transaction;
  
  public class HibernateTestApplication {
  
      public static void main(String[] args) {
          HibernateTestApplication hibernateTestApplication = new HibernateTestApplication();
          int userId = hibernateTestApplication.addUser("Tom", 21);
          System.out.println(userId);
      }
  
      public int addUser(String name, int age){
          HibernateUtil hibernateUtil = HibernateUtil.getInstance();
          SessionFactory sessionFactory = hibernateUtil.getSessionFactory();
          Session session = sessionFactory.openSession();
          Transaction tx = null;
          int userId = 0;
  
          try{
              tx = session.beginTransaction();
              Users user = new Users(name, age);
              userId = (Integer) session.save(user);
              tx.commit();
          }catch (HibernateException e) {
              if (tx!=null) tx.rollback();
              e.printStackTrace();
          }finally {
              session.close();
          }
  
          return userId;
      }
  }
  </code></pre>
  
  <p><strong>I hope you can patiently read the code above, and find the real problem to my code, thx!</strong></p>