Unknown Entity exception while running hibernate 5.0.1 program
<p>I am getting the below error while running my Hibernate program on Hibernate 5.0.1:</p>

<pre><code>Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.abhinav.hibernate.UserDetails
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1542)
at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:225)
at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:499)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:99)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:778)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:751)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:756)
at com.abhinav.hibernate.main.HibernateTest.main(HibernateTest.java:26)
</code></pre>

<p><strong>Below is the configuration file:</strong></p>

<p>
   </p>

<p></p>

<pre><code>&lt;session-factory&gt;

    &lt;!-- Database connection settings --&gt;
    &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
    &lt;property name="connection.url"&gt;jdbc:postgresql://localhost:5432/hibernatedb&lt;/property&gt;
    &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
    &lt;property name="connection.password"&gt;password&lt;/property&gt;

    &lt;!-- JDBC connection pool (use the built-in) --&gt;
    &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;

    &lt;!-- SQL dialect --&gt;
    &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;

    &lt;!-- Disable the second-level cache  --&gt;
    &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;

    &lt;!-- Echo all executed SQL to stdout --&gt;
    &lt;property name="show_sql"&gt;true&lt;/property&gt;

    &lt;!-- Drop and re-create the database schema on startup --&gt;
    &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;


    &lt;mapping resource="com.abhinav.hibernate.UserDetails"/&gt;

&lt;/session-factory&gt;
</code></pre>

<p></p>

<p><strong>The main class:</strong></p>

<pre><code>package com.abhinav.hibernate.main;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

import com.abhinav.hibernate.UserDetails;

public class HibernateTest {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    UserDetails userDetails = new UserDetails();

    userDetails.setUserId(1);
    userDetails.setUserName("Abhinav");

    Configuration configuration = new Configuration().configure();
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());     
    SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());
    Session session = sessionFactory.openSession();
    session.getTransaction();
    System.out.println("Session: "+session);

    // session.save(userDetails);
    session.persist(userDetails);

    System.out.println("Session after save: "+session+" User details: "+userDetails.getUserId()+" "+userDetails.getUserName());
session.getTransaction().commit();
}
</code></pre>

<p><strong>Entity Class:</strong> <code>UserDetails</code> with fields <code>userId</code> and <code>userName</code>.</p>