您正在使用anotation编写一个简单的hibernate程序,下面是我的hibernate.cfg.xml文件:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:XE</property>
<property name="connection.username">vikas</property>
<property name="connection.password">vikas</property>>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</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">create</property>
<!-- Name the annotated Entity -->
<mapping class="org.vikas.hibernate.dto.UserDetails"></mapping>
</session-factory>
当我试图朗读我的程序时,它会引发异常:
16:41:07.592 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML:
/hibernate.cfg.xml(56) The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
16:41:07.599 [main] ERROR org.hibernate.cfg.Configuration - problem parsing configuration/hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
at org.vikas.hibernate.dto.MainTest.main(MainTest.java:18)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
... 3 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 56; columnNumber: 23; The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
... 3 more
请你告诉我,我哪里出错了。
答案 0 :(得分:1)
问题是文件中有一个错误的字符或缺少字符。
例如在行
中 <property name="connection.password">vikas</property>>
你有一个额外的'&gt;'在末尾。我不知道这是错误还是在您删除评论时发生的错误。如果这不是错误,那么请查看其他错误字符。这甚至可能是一个看不见的角色(但不是一个简单的空间,它们是无害的)。有一次它发生在我身上,错误是</hibernate-configuration>
标记后缺少换行符。