• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Hibernate table per class hierarchy

 
Greenhorn
Posts: 17
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
author
Posts: 9050
21
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's move this over to a more appropriate forum...
 
Hemakanta Sethi
Greenhorn
Posts: 17
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



Thank you Bert
I am moving my topic to appropriate forum
 
Greenhorn
Posts: 5
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 28346
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic