Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invalid Mapping Exception while inserting data through hibernate

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am getting this error message while I try to insert data through hibernate.

Exception in thread "main" org.hibernate.InvalidMappingException: Could not pars
e mapping document from resource Person.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:1587)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a: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 org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at PersonMain.openSession(PersonMain.java:33)
at PersonMain.main(PersonMain.java:14)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping docume
nt from invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502
)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "class" mu
st match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite
-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-t
o-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|pr
imitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql
-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Un
known Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown S
ource)
at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)

at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
n Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499
)
... 9 more


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

<hibernate-mapping>

<class name="Person" table="person" >

<property name="person_ID" type="java.lang.String" column="ID" />
<property name="typeOfPerson" type="java.lang.String" column="type" />
<property name="FirstName" type="java.lang.String" column="firstname" />
<property name="LastName" type="java.lang.String" column="Lastname"/>
<property name="Address" type="java.lang.String" column="Address1"/>
<property name="Address2" type="java.lang.String" column="Address2"/>
<property name="City" type="java.lang.String" column="City"/>
<property name="state" type="java.lang.String" column="State"/>
<property name="emailAddress" type="java.lang.String" column="EmailAddress"/>
<property name="zipcode" type="java.lang.Integer" column="Zipcode"/>
<property name="dept_ID" type="java.lang.String" column="DeptID"/>
<property name="country" type="java.lang.String" column="Country"/>
<property name="phone" type="java.lang.String" column="Phone"/>
<property name="officeDay" type="java.lang.String" column="officeDay"/>
<property name="officeTime" type="java.lang.String" column="officeTime"/>

</class>

</hibernate-mapping>


Any help greatly appreciated.

Reagards,
Tom
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This error happens at startup, not insert time, and yes, the mapping file should be corrected by adding an <id>.
reply
    Bookmark Topic Watch Topic
  • New Topic