Hi!
I get below error when starting up my application using Hibernate as a plugin in Struts.
I have mapped all classes in hibernate.cfg.xml, but if I'm not adding the line .addClass(Article.class) I get org.hibernate.MappingException.
now I just get org.hibernate.InvalidMappingException
Hibernate works perfectly when I run my Unit tester as Java Application in Eclipse so there should not be any problems with my .hbm.xml files.
below code for plugin, it is directly from here
http://www.hibernate.org/105.html
Code:
import java.net.URL;
import javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
/**
* @author Juha-Matti Valjus
*
*/
public class HibernatePlugin implements PlugIn {
private Configuration config = null;
private SessionFactory factory;
private String configFilePath = "/hibernate.cfg.xml";
public static final String SESSION_FACTORY_KEY = SessionFactory.class.getName();
public void destroy() {
factory.close();
}
public void init(ActionServlet servlet, ModuleConfig config) throws ServletException {
URL url = HibernatePlugin.class.getResource(configFilePath);
this.config = new Configuration().configure(url)
.addClass(Article.class)
.addClass(Contact.class)
.addClass(Definition.class)
this.factory = this.config.buildSessionFactory();
servlet.getServletContext().setAttribute(SESSION_FACTORY_KEY, factory);
}
}
Directory structure:Code:
Application
|
+-src
| |
| +-package
| -HibernatePlugin
| - Article.java
| - Article.hbm.xml
| - etc...
|
|
+-Webcontent
|
+-WEB-INF
- hibernate.cfg.xml
- etc...
Hibernate version:
3.2.0 GA
Apache Tomcat version:
5.5.17
Full stack trace of any exception that occurs:
org.hibernate.InvalidMappingException: Could not parse mapping document from resource persistencebeans/Analysis.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:544)
at persistencebeans.HibernatePlugin.init(HibernatePlugin.java:41)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:884)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:356)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: org.hibernate.DuplicateMappingException: Duplicate collection role mapping persistencebeans.Analysis.hits
at org.hibernate.cfg.Mappings.addCollection(Mappings.java:124)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2056)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2031)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
at org.hibernate.cfg.Configuration.add(Configuration.java:424)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:465)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:541)
... 21 more
Servlet /Tilannekuvajarjestelma threw load() exception
javax.servlet.UnavailableException
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:893)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:356)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1105)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3917)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4201)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
[code]