This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid Mapping Exception while inserting data through hibernate

 
Tom Hopkins
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Edvins Reisons
Ranch Hand
Posts: 364
  • 0
  • Mark post as helpful
  • send pies
  • 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>.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic