Could not parse mapping document from resource cn/spt/model/Student.hbm.xml

初始hibernate, 写第一个程序 helloworld的错误:

Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/spt/model/Student.hbm.xml

    at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)

    at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)

    at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)

    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)

    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)

    at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)

    at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)

    at cn.spt.mgr.StudentManager.main(StudentManager.java:22)

Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping

    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:549)

    at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)

    ... 7 more

Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; 文档无效: 找不到语法。

    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)

    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:437)

    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)

    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)

    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:228)

    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)

    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)

    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)

    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)

    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)

    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:648)

    at org.dom4j.io.SAXReader.read(SAXReader.java:465)

    at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)

    ... 8 more

 Google一下, 发现需要在即将被mapping的 cn/spt/model/Student.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"> 

 

你可能感兴趣的:(document)