Hibernate Mapping Exception : Unknown Entity
<p>I am mapping a simple POJO to a database table in SQL server using xml file mapping.  I am getting Hibernate Mapping Exception : Unknown Entity<br>
These are my code files:<br>
Entry point class :   </p>

<pre><code>public class Program {

    public static void main(String[] args) {
        System.out.println("Helo World");

        Session session = HibernateUtilities.getSessionFactory().openSession();
        session.beginTransaction();

        User user = new User();
        user.setId(1);
        user.setName("Ajay");
        user.setGoal(100);
        user.setTotal(0);

        session.save(user);

        session.getTransaction().commit();
        session.close();
        HibernateUtilities.getSessionFactory().close();
        System.out.println("session closed");
    }

}
</code></pre>

<p>this is HibernateUtilities class:</p>

<pre><code>public class HibernateUtilities {
        private static SessionFactory sessionFactory;
        private static ServiceRegistry serviceRegistry;
        static {
            try {
                Configuration configuration = new Configuration().configure();
                serviceRegistry = new StandardServiceRegistryBuilder()
                        .applySettings(configuration.getProperties()).build();
                sessionFactory = configuration.buildSessionFactory(serviceRegistry);
            } catch (HibernateException e) {
                System.out.println(e);
            }
        }

        public static SessionFactory getSessionFactory(){
            return sessionFactory;
        }

}
</code></pre>

<p>this is POJO User :   </p>

<pre><code>public class User {
    private int id;
    private String name;
    private int total;
    private int goal;

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getGoal() {
        return goal;
    }

    public void setGoal(int goal) {
        this.goal = goal;
    }

    public void setId(int id) {
        this.id = id;
    }
}
</code></pre>

<p>This is Mapping file :   </p>

<pre><code>&lt;?xml version="1.0"?&gt;
    &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
    &lt;!-- Generated Sep 14, 2016 11:58:02 AM by Hibernate Tools 3.4.0.CR1 --&gt;
    &lt;hibernate-mapping package="com.example.hibernate"&gt;
     &lt;class entity-name="User" name="com.example.hibernate.User" table="USERS"&gt;
      &lt;id name="id" type="int"&gt;
       &lt;column name="ID"/&gt;
       &lt;generator class="increment"/&gt;
      &lt;/id&gt;
      &lt;property generated="never" lazy="false" name="name" type="java.lang.String"&gt;
       &lt;column name="NAME"/&gt;
      &lt;/property&gt;
      &lt;property generated="never" lazy="false" name="total" type="int"&gt;
       &lt;column name="TOTAL"/&gt;
      &lt;/property&gt;
      &lt;property generated="never" lazy="false" name="goal" type="int"&gt;
       &lt;column name="GOAL"/&gt;
      &lt;/property&gt;
     &lt;/class&gt;
    &lt;/hibernate-mapping&gt;
</code></pre>

<p>this is configuration file :   </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 name=""&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
      &lt;property name="hibernate.connection.password"&gt;ajay1994&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:sqlserver://localhost:1433;databaseName=protein_tracker&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;test&lt;/property&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt;
      &lt;mapping class="com.example.hibernate.User" resource="com/example/hibernate/User.hbm.xml"/&gt;
     &lt;/session-factory&gt;
    &lt;/hibernate-configuration&gt;
</code></pre>

<p>Stack Trace for Error : </p>

<pre><code>Helo World
Sep 14, 2016 2:58:58 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.2.Final}
Sep 14, 2016 2:58:58 PM org.hibernate.cfg.Environment &lt;clinit&gt;
INFO: HHH000206: hibernate.properties not found
Sep 14, 2016 2:58:58 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Sep 14, 2016 2:58:58 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
Sep 14, 2016 2:58:58 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Sep 14, 2016 2:58:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Sep 14, 2016 2:58:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost:1433;databaseName=protein_tracker]
Sep 14, 2016 2:58:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=test, password=****}
Sep 14, 2016 2:58:58 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Sep 14, 2016 2:58:58 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections &lt;init&gt;
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Sep 14, 2016 2:58:58 PM org.hibernate.dialect.Dialect &lt;init&gt;
INFO: HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.example.hibernate.User
    at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(MetamodelImpl.java:620)
    at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1604)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:104)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:673)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:660)
    at com.example.hibernate.Program.main(Program.java:18)
</code></pre>