Document root element "hibernate-configuration", must match DOCTYPE root "hibernate-mapping" -
in code im trying map person_details database. configuration file follows hibernate.cfg.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"> <hibernate-configuration> <session-factory> <property name="connection.url"> jdbc:mysql://localhost/test </property> <property name="connection.driver_class"> com.mysql.jdbc.driver </property> <property name="hibernate.connection.username"> root </property> <property name="connection.password"> gopal </property> <property name="connection.pool_size"> 1 </property> <property name="hibernate.dialect"> org.hibernate.dialect.hsqldialect </property> <property name="show_sql"> true </property> <property name="hbm2ddl.auto"> create </property> <mapping resource="com/sixdee/persondetail/pesondetail.hbm.xml" /> </session-factory> </hibernate-configuration>
the mapping xml file below
persondetail.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"> <hibernate-mapping> <class name="com.sixdee.persondetail" table="person_details"> <id name="id" type="integer" column="emp_id"> <generator class="assigned" /> </id> <property name="gender" type="string" column="gender" /> <property name="age" type="integer" colummn="age" /> <property name="dob" type="string" column="dob" /> </class> </hibernate-mapping>
the main class follows persondetailmain.java
package com.sixdee.persondetail; import org.hibernate.hibernateexception; import org.hibernate.session; import org.hibernate.sessionfactory; import org.hibernate.transaction; import org.hibernate.cfg.configuration; public class persondetailmain { public static void main(string[] args) { session session = null; try{ sessionfactory sessionfactory = new configuration().configure().buildsessionfactory(); session=sessionfactory.opensession(); transaction transaction=null; transaction=session.begintransaction(); persondetail person=new persondetail(3,"male",23,"12-06-1990"); session.save(person); transaction.commit(); } catch (nullpointerexception e) { e.printstacktrace(); } catch (hibernateexception e) { e.printstacktrace(); } finally{ if(session!=null){ session.close(); session=null; } } } }
on running main method im getting following errors....
org.hibernate.mappingexception: invalid configuration @ org.hibernate.cfg.configuration.doconfigure(configuration.java:1521) @ org.hibernate.cfg.configuration.configure(configuration.java:1462) @ org.hibernate.cfg.configuration.configure(configuration.java:1448) @ com.sixdee.persondetail.persondetailmain.main(persondetailmain.java:15) caused by: org.xml.sax.saxparseexception: document root element "hibernate-configuration", must match doctype root "hibernate-mapping". @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.createsaxparseexception(errorhandlerwrapper.java:195) @ com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.error(errorhandlerwrapper.java:131) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:384) @ com.sun.org.apache.xerces.internal.impl.xmlerrorreporter.reporterror(xmlerrorreporter.java:318) @ com.sun.org.apache.xerces.internal.impl.dtd.xmldtdvalidator.rootelementspecified(xmldtdvalidator.java:1621) @ com.sun.org.apache.xerces.internal.impl.dtd.xmldtdvalidator.handlestartelement(xmldtdvalidator.java:1900) @ com.sun.org.apache.xerces.internal.impl.dtd.xmldtdvalidator.startelement(xmldtdvalidator.java:764) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.scanstartelement(xmlnsdocumentscannerimpl.java:400) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl$nscontentdriver.scanrootelementhook(xmlnsdocumentscannerimpl.java:626) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next(xmldocumentfragmentscannerimpl.java:3104) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl$prologdriver.next(xmldocumentscannerimpl.java:921) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(xmldocumentscannerimpl.java:647) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(xmlnsdocumentscannerimpl.java:140) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(xmldocumentfragmentscannerimpl.java:511) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:808) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(xml11configuration.java:737) @ com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(xmlparser.java:119) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(abstractsaxparser.java:1205) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse(saxparserimpl.java:522) @ org.dom4j.io.saxreader.read(saxreader.java:465) @ org.hibernate.cfg.configuration.doconfigure(configuration.java:1518) ... 3 more
please me out
doctype <hibernate-configuration>
should be:
<!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd//en" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
Comments
Post a Comment