问题描述
- hiberate报错,代码如下
-
七月 10, 2015 11:34:06 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
七月 10, 2015 11:34:06 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.10.Final}
七月 10, 2015 11:34:06 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
七月 10, 2015 11:34:06 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
七月 10, 2015 11:34:07 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
七月 10, 2015 11:34:07 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2077)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2056)
at StudentTest.main(StudentTest.java:18)
Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; 文档无效: 找不到语法。
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: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:649)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2157)
... 3 more
解决方案
cfg.configure("...") 的文件名参数呢?
解决方案二:
七月 11, 2015 2:15:48 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
七月 11, 2015 2:15:48 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.10.Final}
七月 11, 2015 2:15:48 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
七月 11, 2015 2:15:48 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
七月 11, 2015 2:15:48 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: xz/hibernate/model/Student.hbm.xml
七月 11, 2015 2:15:48 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: xz/hibernate/model/Student.hbm.xml
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2204)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2162)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2077)
at StudentTest.main(StudentTest.java:19)
解决方案三:
//实例化configuration对象
Configuration cfg = new Configuration()
//多次调用addResource()方法,添加映射文件
cfg.addResource("Item.hbm.xml")
cfg.addResource("Bid.hbm.xml");
http://blog.csdn.net/csh624366188/article/details/7578939