Traditional Hibernate Issues (POJO): Part#1 org.hibernate.MappingException: Unknown entity

Unknown Entity exception might have a verity of reasons and causes, however, when you’re using POJO and XML files, since there is no Entity tags and mismatching between JPA nad Hibernate class tags, the reason of this exception might be a little bit challenging. when you’re using POJO with newer version of Hibernate, the main reason might be related to the way you are initiating SessionFactory.something like below…


INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
 org.hibernate.MappingException: Unknown entity: com.navid.practice.hibernate.User
 at org.hibernate.metamodel.internal.MetamodelImpl.entityPersister(
 at org.hibernate.internal.SessionImpl.getEntityPersister(
 at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(
 at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(
 at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(
 at org.hibernate.internal.SessionImpl.fireSave(
 at com.navid.practice.hibernate.Program.main(

the issue was related to the version of Hibernate that I had, 5.x and the code that I wrote for init the SessionFactory:

public class HibernateUtilities {

private static ServiceRegistry svcReg = null;
 private static SessionFactory sessionFactory = null;

static {

try {
 Configuration cfg = new Configuration().configure();

svcReg = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
 sessionFactory = cfg.buildSessionFactory(svcReg);

} catch (HibernateException e) {
 System.out.println("An Error in init the SessionFactory!");



the issue could be resolved just by changing the SessionFactory creation line …

sessionFactory = cfg.buildSessionFactory();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s