title: UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0)
body: <p>In the code below when I try to execute <code>Main.java</code> I am getting exception:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.UnknownEntityTypeException: Unable to locate persister: com.np.vta.test.pojo.Users
      at org.hibernate.internal.SessionFactoryImpl.locateEntityPersister(SessionFactoryImpl.java:792)
      at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2637)
      at org.hibernate.internal.SessionImpl.access$2500(SessionImpl.java:164)
      at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.&lt;init&gt;(SessionImpl.java:2575)
      at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.&lt;init&gt;(SessionImpl.java:2562)
      at org.hibernate.internal.SessionImpl.byId(SessionImpl.java:1044)
      at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
      at com.app.test.Main.main(Main.java:20)
  </code></pre>
  
  <p>but if I do uncomment <code>cfg.addClass( Users.class ).addResource( "com/np/vta/test/pojo/Users.hbm.xml" );</code> then the code works fine.</p>
  
  <p>Why it is not reading the <code>&lt;mapping&gt;</code> from <code>hibernate.cfg.xml</code>?</p>
  
  <hr>
  
  <h2>Project setup</h2>
  
  <p><a href="https://i.stack.imgur.com/5nto3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5nto3.jpg" alt="project setup eclipse"></a></p>
  
  <hr>
  
  <h2>hibernate.cfg.xml</h2>
  
  <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;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
          &lt;property name="hibernate.connection.password"&gt;root@123321&lt;/property&gt;
          &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://192.168.1.90:3306/test&lt;/property&gt;
          &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
          &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
          &lt;mapping resource="com/np/vta/test/pojo/Users.hbm.xml" class="com.np.vta.test.pojo.Users" /&gt;
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <hr>
  
  <h2>Users.hbm.xml</h2>
  
  <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 24 Aug, 2015 3:57:45 PM by Hibernate Tools 3.4.0.CR1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="com.np.vta.test.pojo.Users" table="tomcat_users"&gt;
          &lt;id name="userName" type="java.lang.String"&gt;
              &lt;column name="user_name" /&gt;
              &lt;generator class="assigned" /&gt;
          &lt;/id&gt;
          &lt;property name="password" type="java.lang.String"&gt;
              &lt;column name="password" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <hr>
  
  <h2>Users.java</h2>
  
  <pre><code>package com.np.vta.test.pojo;
  
  import java.io.Serializable;
  
  public class Users implements Serializable
  {
      private static final long serialVersionUID = 7855937172997134350L;
      private String            userName;
      private String            password;
  
      public Users()
      {
      }
      // getter and setters
  }
  </code></pre>
  
  <hr>
  
  <h2>Main.java</h2>
  
  <pre><code>package com.app.test;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  
  import com.np.vta.test.pojo.Users;
  
  public class Main
  {
      public static void main( String[] args )
      {
          Configuration cfg = new Configuration();
          cfg.configure( "hibernate.cfg.xml" );
          //        cfg.addClass( Users.class ).addResource( "com/np/vta/test/pojo/Users.hbm.xml" );
          StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder().applySettings( cfg.getProperties() );
          SessionFactory sessionFactory = cfg.buildSessionFactory( registryBuilder.build() );
          Session session = sessionFactory.openSession();
          Users users = session.get( Users.class, "anand" );
          System.out.println( users );
      }
  }
  </code></pre>