0

I got problem,could not parsing configuration hiberenate.cfg.xml

<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521/XE</property>
<property name="connection.username">system</property>
<property name="connection.password">system</property>
<property name="dialect">org.hibernate.OracleDialect</property>
<property name="show_sql">true</property>
<mapping calss="com.jlcindia.hibernate/Customer"/>
</session-factory>
</hibernate-configuration>   

Here is the exception...

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.jlcindia.hibernate.AHLab2Client.main(AHLab2Client.java:15)
Caused by: org.hibernate.HibernateException: problem parsing
configurationhibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1291)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at com.jlcindia.hibernate.AHibernateUtil.<clinit>(AHibernateUtil.java:15)
... 1 more
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1287)
... 3 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 25; Document
is invalid: no grammar found.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown 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.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
atorg.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.
scanRootElementHook(Unknown Source) at org.apache.xerces.impl.
XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 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:334)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1286)
... 3 more

I checked my DB and all the tag here but i am also not able to solve it. plese help me.

4

2 回答 2

1

There are 2 mistakes with this line

<mapping calss="com.jlcindia.hibernate/Customer"/>
  1. class is mis-spelled as calss.

  2. com.jlcindia.hibernate/Customer should have been com.jlcindia.hibernate.Customer - I'm assuming that this is the entity class.

After correcting the 2 mistakes, that line should something like this

<mapping class="com.jlcindia.hibernate.Customer" />

Side Note: A good IDE would have highlighted the error in the xml file then and there(with where exactly the error is). I suggest you use one(in case you're not using any).

于 2013-10-17T15:43:33.383 回答
0

The stacktrace is stating that the doctype header is missing - add the line

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

at the start of the XML configuration file

There is an additional / which is terminating the tag early also a "class" typo both in the mapping tag . Replace

<mapping calss="com.jlcindia.hibernate/Customer"/>

with

<mapping class="com.jlcindia.hibernate.Customer"/>
于 2013-10-17T15:43:15.463 回答