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
}