Skip to content
Advertisement

Error when try to persist entity with Hibernate (MappingException: Unknown entity)

I’m using Hibernate 5.0.6 and Hibernate annotations 3.5.6-Final with MySql 5.1.37 in a standalone maven java application.

I’m trying to make a simply persistence example work but I receive the following error when I call save:

JavaScript

The classes Is pointed via mapping class in the configuration file. But it is unable to find.

JavaScript

But when I do this in HibernateUtil:

JavaScript

It works. But I want to point mapping the classes in xml files.

I found several errors related to this but found no solution solved my problem. I think I’m doing something wrong.

The full stacktrace of error:

JavaScript

The config file is locate at: projectsrcmainresourceshibernate.cfg.xml

JavaScript

HibernateUtil:

JavaScript

The POJO class:

JavaScript

Advertisement

Answer

It is already a familiar problem with Hibernate 5 configuration building. You can’t use Hibernate 4 configuration approach to configure Hibernate 5. So just use this

JavaScript

You can refer this for additional notes. I have implemented a configuration builder that works fine with Hibernate 4 and Hibernate 5, you can take a look on it too ConfigurationBuilder.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement