首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Hibernate异常求解

2012-05-03 
Hibernate错误求解hibernate.cfg.xml内容如下XML code?xml version1.0 encodingutf-8?hibernate-

Hibernate错误求解
hibernate.cfg.xml内容如下

XML code
<?xml version='1.0' encoding='utf-8'?><hibernate-configuration        xmlns="http://www.hibernate.org/xsd/hibernate-configuration"        xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <session-factory>    <!-- Database connection settings -->    <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>    <property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=stu_sys</property>    <property name="connection.username">sa</property>    <property name="connection.password">123456</property>    <!-- JDBC connection pool (use the built-in) -->    <property name="connection.pool_size">1</property>    <!-- SQL dialect -->    <property name="dialect">org.hibernate.dialect.SQLServer2005Dialect</property>    <!-- Enable Hibernate's automatic session context management -->    <property name="current_session_context_class">thread</property>    <!-- Disable the second-level cache  -->    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>    <!-- Echo all executed SQL to stdout -->    <property name="show_sql">true</property>    <!-- Drop and re-create the database schema on startup -->    <property name="hbm2ddl.auto">update</property>    <mapping resource="DAO/grade.hbm.xml"/>  </session-factory></hibernate-configuration>


控制台显示的错误:
2012-5-1 16:58:48 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2012-5-1 16:58:48 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.2.Final}
2012-5-1 16:58:48 org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.c3p0.timeout=1800, hibernate.connection.driver_class=com.microsoft.sqlserver.jdbc.SQLServerDriver, hibernate.c3p0.max_statements=50, hibernate.dialect=org.hibernate.dialect.SQLServer2005Dialect, hibernate.c3p0.max_size=20, hibernate.c3p0.min_size=5, hibernate.connection.username=sa, hibernate.connection.url=jdbc:sqlserver://localhost:1433;DatabaseName=stu_sys, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****}
2012-5-1 16:58:48 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2012-5-1 16:58:48 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2012-5-1 16:58:48 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:2009)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1926)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1905)
at DAO.gradeManager.main(gradeManager.java:18)
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)


at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:250)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3095)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:921)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
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:807)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2006)
... 3 more
大家帮忙看看,问题出在哪里了

[解决办法]
Caused by: org.xml.sax.SAXParseException: Document is invalid: no grammar found.
文档非法,找不到语法解析。

把hbm文件中的第二行删掉,就是这行:
<!-- 指定Hibernate映射文件的DTD信息 -->
删除掉,把“<!DOCTYPE”这行提到第二行试试看。

热点排行