-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Tomcat,Struts,Hibernate InvalidMappingException
PostPosted: Tue Nov 28, 2006 5:00 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
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]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 6:24 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Post Analysis.hbm.xml and its POJO.

_________________
andresgr (--don't forget to rate)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 7:06 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
       
<hibernate-mapping>
   
   <class name="persistencebeans.Analysis" table="Analysis">
      
      <id name="id" column="id" type="java.lang.Integer">
         <generator class="sequence">
           <param name="sequence">analysis_id_seq</param>
          </generator>
      </id>
      
      <property name="timestamp"
              column="timestamp"
              not-null="true"/>
           
        <set name="hits" table="Hit" inverse="true" cascade="all">
              <key column="analysis_id" />
               <one-to-many class="persistencebeans.Hit" />
        </set>
       
        <set name="articles" table="Analysis_has_article">
              <key column="analysis_id"/>
              <many-to-many class="persistencebeans.Article" column="article_id"/>
        </set>
                   
   </class>
   
</hibernate-mapping>

Code:
/**
*
*/
package persistencebeans;

import java.sql.Timestamp;
import java.util.Set;

/**
* Analysis.java
*
* @author Juha-Matti Valjus
*/

public class Analysis {

   private int id;
   private Timestamp timestamp;
   private Set<Hit> hits;
   private Set<Article> articles;
   
   /**
    * Class constructor
    */
   public Analysis() {

   }
   
   public Set<Article> getArticles() {
      return articles;
   }

   public void setArticles(Set<Article> articles) {
      this.articles = articles;
   }

   /**
    * @return the id
    */
   public int getId() {
      return id;
   }

   /**
    * @param id the id to set
    */
   public void setId(int id) {
      this.id = id;
   }

   /**
    * @return the timestamp
    */
   public Timestamp getTimestamp() {
      return timestamp;
   }

   /**
    * @param timestamp the timestamp to set
    */
   public void setTimestamp(Timestamp timestamp) {
      this.timestamp = timestamp;
   }

   public Set<Hit> getHits() {
      return hits;
   }

   public void setHits(Set<Hit> hits) {
      this.hits = hits;
   }
   

}



Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 8:16 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
Hi!

Problem solved itself..
There must have been some sort of typing error somewhere, because when I did release + checkout it begin to work. Odd enough the same problem was on everybodys copy of the cvs, so I really don't know what was wrong.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.