torres
torres

Reputation: 11

Element type "hibernate-configuration" must be declared

In my code I am trying to map person_details from database. the configuration file is as follows hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <property name="dialect">
        org.hibernate.dialect.MySQLDialect
    </property>
    <property name="connection.driver_class">
        com.mysql.jdbc.Driver
    </property>

    <!-- Assume test is the database name -->
    <property name="connection.url">
        jdbc:mysql://localhost/EMP
    </property>
    <property name="connection.username">
        root
    </property>
    <property name="connection.password">
        root
    </property>


    <!-- List of XML mapping files -->
    <mapping resource="employee.hbm.xml" />
    <mapping class="newmavenproject.hibernateexample.CRUDS.Employee" />

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

the mapping xml file is as below

employee.hbm.xml

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

<hibernate-mapping>
<class  table="Employee" name="newmavenproject.hibernateexample.CRUDS.Employee">
  <id name="id" type="int" column="id">
     <generator class="native"/>
  </id>
  <property name="age" column="age" type="int"/>
  <property name="firstName" column="first" type="string"/>
  <property name="lastName" column="last" type="string"/>

</class>
</hibernate-mapping>

On running the application I am getting the below error .Please help as I cant find any thing for fixing this out.

Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2241)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
at    newmavenproject.hibernateexample.CRUDS.CrudsOps.main(CrudsOps.java:13)
Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 26; Element type "hibernate-configuration" must be declared.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1906)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:742)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:374)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:613)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3132)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:852)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238)
... 3 more

Upvotes: 1

Views: 5143

Answers (1)

N&#225;ndor Előd Fekete
N&#225;ndor Előd Fekete

Reputation: 7098

You're trying to define a hibernate configuration, but the DTD file you're referencing in the xml wrongly points to http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd. Change your DOCTYPE declaration to

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

Upvotes: 1

Related Questions