-->
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.  [ 3 posts ] 
Author Message
 Post subject: org.xml.sax.SAXParseException: "class" must match
PostPosted: Sat Sep 19, 2009 6:09 am 
Newbie

Joined: Sat Sep 19, 2009 5:49 am
Posts: 2
Hello,
I am new to hibernate and trying to implement inheritance using table per class hierary.

here i am providing the code and exception i have encountered.

When i try to load the data created in database,getting the following error message.

java.lang.ExceptionInInitializerError
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource EmployeeDetails.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:602)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1621)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1448)
at com.anreddy.EmployeeTestCase.getSession(EmployeeTestCase.java:12)
at com.anreddy.EmployeeTestCase.<clinit>(EmployeeTestCase.java:9)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:535)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:599)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:532)
... 9 more
Exception in thread "main"

Here is my Employeedetails.hbm.xml

Code:
<hibernate-mapping package="com.anreddy">
   <class name="Employee" table="EMPLOYEE_DETAILS" schema="ANREDDY">
      <id name="empno" type="integer">
         <column name="EMPNO" precision="22" scale="0" />
         <generator class="increment" />
      </id>
      <property name="name" type="string">
         <column name="NAME" length="20" />
      </property>
      <discriminator column="type" />
      <subclass name="HourleyEmployee" discriminator-value="hourly">
         <property name="hourlyRate" type="double">
            <column name="HOURLY_RATE" precision="10" />
         </property>
         <property name="maxHoursPerDay" type="integer">
            <column name="MAX_HOURS_PER_DAY" precision="22" scale="0" />
         </property>
      </subclass>
      <subclass name="SalariedEmployee" discriminator-value="salaried">
         <property name="annualSalary" type="double">
            <column name="ANNUAL_SALARY" precision="10" />
         </property>
      </subclass>
   </class>
</hibernate-mapping>


Here is my Employee.java

Code:
public abstract class Employee implements java.io.Serializable {
   private Integer empno;
   private String name;
            //setters and getters
}

Here is the HourlyEmployee.java file

Code:
public class HourlyEmployee extends Employee {
   private Integer maxHoursPerDay;
   private Double hourlyRate;
             // setters and getters
}

Here is my SalariedEmployee.java file
Code:
public class SalariedEmployee extends Employee {
   private Double annualSalary;
             // setters and getters
}



Top
 Profile  
 
 Post subject: Re: org.xml.sax.SAXParseException: "class" must match
PostPosted: Sat Sep 19, 2009 6:53 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi anreddy4u,

you have a problem with the order of the elements within your <class> element.

Your mapping files reads like this (shortened):
Code:
<hibernate-mapping package="com.anreddy">
   <class name="Employee" table="EMPLOYEE_DETAILS" schema="ANREDDY">
      <id name="empno" type="integer">
         <column name="EMPNO" precision="22" scale="0" />
         <generator class="increment" />
      </id>
      <property name="name" type="string">
         <column name="NAME" length="20" />
      </property>
      <discriminator column="type" />
      <subclass...>
      ...
      </subclass>
      ...
  </class>


You have to place the <discriminator> element right after the <id> element without anything else in between. So make it this way and it should work:
Code:
<hibernate-mapping package="com.anreddy">
   <class name="Employee" table="EMPLOYEE_DETAILS" schema="ANREDDY">
      <id name="empno" type="integer">
         <column name="EMPNO" precision="22" scale="0" />
         <generator class="increment" />
      </id>
      <discriminator column="type" />
      <property name="name" type="string">
         <column name="NAME" length="20" />
      </property>
      <subclass...>
      ...
      </subclass>
      ...
  </class>


CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: org.xml.sax.SAXParseException: "class" must match
PostPosted: Sun Sep 20, 2009 11:22 am 
Newbie

Joined: Sat Sep 19, 2009 5:49 am
Posts: 2
thanks a lot..its working now :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.