aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate table per class hierarchy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate table per class hierarchy" Watch "Hibernate table per class hierarchy" New topic
Author

Hibernate table per class hierarchy

Hemakanta Sethi
Greenhorn

Joined: Jul 19, 2011
Posts: 17

Hi.. Friends
I am trying to solve the below Exception, but i could not.

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from
resource payment.hbm.xml

Below i give the all the related files.
1. Exception Details
2. Payment.java
3. payment.hbm.xml
4. hibernate.cfg.xml
5. CreditCardPayment.java
6. ChequePayment.java
7. Client1.java

Can anyone please guide me on how to resolve this issue.
Below are the details of the Exception.



Exception Details
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from
resource payment.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at Client1.main(Client1.java:14)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 6 more
Caused by: org.xml.sax.SAXParseException: Attribute "colume" must be declared for element type "discrimi
nator".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHand
lerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:13
1)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:38
4)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:31
8)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XML
DTDValidator.java:1275)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidato
r.java:1940)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java
:785)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocume
ntScannerImpl.java:377)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.
next(XMLDocumentFragmentScannerImpl.java:2755)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.ja
va:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImp
l.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocume
ntFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:8
08)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:7
37)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:120
5)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:
522)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499)




Payment.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Payment.java
public class Payment
{
private int paymentId;
private double amount;

public void setPaymentId(int paymentId)
{
this.paymentId=paymentId;
}
public int getPaymentId()
{
return paymentId;
}
public void setAmount(double amount)
{
this.amount=amount;
}
public double getAmount()
{
return amount;
}

}


payment.hbm.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<!-- payment.hbm.xml -->

<hibernate-mapping>
<class name="Payment" table="PAYMENT" >

<id name="paymentId" column="PAYID">
<generator class="assigned"/>
</id>
<!-- <discriminator> element always immediately after <id> element -->
<discriminator colume="PMODE" type="java.lang.String" length="10" />

<property name="amount"/>

<subclass name="CreditCardPayment" discriminator-value="CC">
<property name="cardType" column="CCTYPE" length="10" />
</subclass>

<subclass name="ChequePayment" discriminator-value="CH">
<property name="chequeType" column="CHTYPE" length="10" />
</subclass>

</class>
</hibernate-mapping>


hibernate.cfg.xml
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- hibernate.cfg.xml -->

<hibernate-configuration>
<session-factory>

<!-- connectio properties -->

<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbcracle:thin:@localhost:1521:SATYA</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>

<!-- hibernate properties -->

<property name="show_sql">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>

<property name="hbm2ddl.auto">update</property>

<!-- mapping resourses -->

<mapping resource="payment.hbm.xml"/>

</session-factory>
</hibernate-configuration>


CreditCardPayment.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CreditCardPayment.java

public class CreditCardPayment extends Payment
{
private String cardType;

public void setCardType(String cardType)
{
this.cardType=cardType;
}
public String getCardType()
{
return cardType;
}

}


ChequePayment.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// ChequePayment.java

public class ChequePayment extends Payment
{
private String chequeType;

public void setChequeType(String chequeType)
{
this.chequeType=chequeType;
}
public String getChequeType()
{
return chequeType;
}

}



Client1.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Client1.java
*
*
*/

import org.hibernate.*;
import org.hibernate.cfg.*;

public class Client1
{
static public void main(String client[])
{
SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Session session= factory.openSession();


CreditCardPayment ccp= new CreditCardPayment();
ccp.setPaymentId(101);
ccp.setCardType("VISA");
ccp.setAmount(3000);


ChequePayment chp= new ChequePayment();
chp.setPaymentId(101);
chp.setChequeType("order");
chp.setAmount(3000);


Transaction tx= session.beginTransaction();
session.save(ccp);
session.save(chp);
tx.commit();
System.out.println("Done....");

session.close();
factory.close();


}
}

I rechecked the xml mapping file many times still i could not able to find out the error. Can anyone please guide me on how to resolve this issue?

Advanced Thanks....
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
Let's move this over to a more appropriate forum...


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Hemakanta Sethi
Greenhorn

Joined: Jul 19, 2011
Posts: 17

Bert Bates wrote:Let's move this over to a more appropriate forum...


Thank you Bert
I am moving my topic to appropriate forum
Mahajan Nikhil
Greenhorn

Joined: Jul 30, 2011
Posts: 5

Attribute 'colume' is spelled wrong . It should be 'column'. Hence your tag would be

<discriminator colume="PMODE" type="java.lang.String" length="10" />

I hope that solves your prob.
Hemakanta Sethi
Greenhorn

Joined: Jul 19, 2011
Posts: 17

Mahajan Nikhil wrote:Attribute 'colume' is spelled wrong . It should be 'column'. Hence your tag would be

<discriminator colume="PMODE" type="java.lang.String" length="10" />

I hope that solves your prob.


Thank you Mr. Mahajan Nikhil.
I got the error.
Any technique to find the error easily. If present please tell me.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

Hemakanta Sethi wrote:Any technique to find the error easily. If present please tell me.


Reading the error messages is the technique I recommend. In this case one of the error messages mentioned a column name which was a problem. That means you should look at the place where that column name was mapped. This particular problem had completely self-explanatory error messages, all you would have to do is to read them and follow up on what they said.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate table per class hierarchy
 
Similar Threads
Hibernate table per class hierarchy
Please help me .....Hibernate Expertise Required
Querying from inheritance hierarchy
Could not parse mapping document from resource developerhelpway/hibernate/employee.hbm.xml
Could not parse configuration: /hibernate.cfg.xml