Hibernate MappingException error

Share

When using Hibernate in a project, correct configuration of the service is a must, otherwise errors won’t let you alone 🙂 Following the basic steps of configuration, I found myself facing an error, of which cause made no sense on the moment because I thought my configuration were correct.

In the hibernate.cfg.xml file, sessionFactory was created, with the necessary details to connect to the database and I had the mapping details for mapping the domain objects to the database tables.
After creating all the hbm.xml files needed, previously declared in the configuration file, I just had to run the project in tomcat and see the result of the logic implemented in controller.
This is the error that appeared:


DEBUG DefaultSaveOrUpdateEventListener(entityIsDetached:205) - updating detached instance
ERROR StandardWrapperValve(invoke:260) - Servlet.service() for servlet TestServlet threw exception
org.hibernate.MappingException: Unknown entity: domain.ro.test.TestServlet
org.hibernate.impl.SessionFactoryImpl.getEntityPersister
(SessionFactoryImpl.java:550)
org.hibernate.impl.SessionImpl.getEntityPersister
(SessionImpl.java:1338)
org.hibernate.event.def.AbstractSaveEventListener.
saveWithGeneratedId(AbstractSaveEvent
.........

Debuging the application and displaying in the console of Eclipse Hibernate details, I saw that it recognized at initialization about the hbm.xml files, but when having to commit data, so using them in particular, it did not recognized them anymore, throwing the error above…

”org.hibernate.MappingException”

An example from an hbm.file:

class name=”test.domain.TestConfig” table=”test_config” entity-name=”TestConfig”

At first glance, the code looked correct to me, thus I couldn’t understood the error. After documenting about this error, I found that a possible problem was setting the entity-name of a annotation class in hbm.xml file. Which in my case deleting the entity-name from the xml file was the sollution. 😀

The element simply maps the object with the coresponding database table. Creates a tie between the elements from your object and the fields from the database table. The Class element has some properties the programmer cand choose to make use of, or not. More details HERE.

Entity-name should be used when you have a class and want to map it to more than one table. For instance, there are two tables that have fields in common. Instead of creating two different persistence classes, you use only one, with help from the “entity-name” property you can distinguish which fields are from which table.

entity-name=”TestConfig1″


entity-name=”TestConfig2″

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close