[Solved] org.hibernate.MappingException: Unknown entity

====1===
org.hibernate.MappingException: Unknown entity: cjq.hibernate.tutorial.domain.Event
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1192)
at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1403)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:757)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:749)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:745)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
at $Proxy4.save(Unknown Source)
at cjq.hibernate.tutorial.web.EventManagerServlet.createAndStoreEvent(EventManagerServlet.java:115)
at cjq.hibernate.tutorial.web.EventManagerServlet.doGet(EventManagerServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:722)

Just started with the following code.
Configuration cfg = new Configuration().addResource(
“cjq/hibernate/tutorial/domain/Event.hbm.xml”).addResource(
“cjq/hibernate/tutorial/domain/Person.hbm.xml”);
return new Configuration().configure().buildSessionFactory();
Here there are two different instances of Configuration. The first instance has the mapping file added, while the second does not. And the second one is returned.
Therefore, an error is reported. This is a relatively low level error.
Change the code to.
Configuration cfg = new Configuration().addResource(
“cjq/hibernate/tutorial/domain/Event.hbm.xml”).addResource(
“cjq/hibernate/tutorial/domain/Person.hbm.xml”);
//return new Configuration().configure().buildSessionFactory();
return cfg.configure().buildSessionFactory();

This will not be the case. Because the same Configuration instance is used now.

Additional notes.

When not configuring some relevant properties in hibernate.cfg.xml, the

The java code is as follows.

Configuration cfg = new Configuration() .addClass(org.hibernate.auction.Item.class) .addClass(org.hibernate.auction.Bid.class) .setProperty(“hibernate.dialect”, “org.hibernate.dialect.MySQLInnoDBDialect”) .setProperty(“hibernate.connection.datasource”, “java:comp/env/jdbc/test”) .setProperty(“hibernate.order_updates”, “true”);

Similar Posts: