爲什麼我嘗試執行main時出現「無法創建sessionFactory object.org.hibernate.MappingException:無效配置」?我正在使用Hibernate 4.2.11.Final和PostGreSQL DB。這是我的hibernate.cfg.xml:無法創建sessionFactory object.org.hibernate.MappingException:無效的配置
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">postgres</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/ProgettoPersonaleDB</property>
<property name="connection_pool_size">1</property>
<property name="hbm2ddl.auto">create</property>
<property name="show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- <mapping class="org.javabrains.sanjaya.dto.UserDetails" /> -->
<mapping resource="Players.hbm.xml" />
<mapping resource="Users.hbm.xml" />
<!-- <mapping class="ProgettoPersonale.src.main.java.ProgettoPersonale.ProgettoPersonale.Users.java"/> -->
<mapping
class="ProgettoPersonale/src/main/java/ProgettoPersonale/ProgettoPersonale/Users.java" />
/
<mapping
class="ProgettoPersonale/src/main/java/ProgettoPersonale/ProgettoPersonale/Players" />
<class-cache class="org.hibernate.auction.Item" usage="read-write"/>
<class-cache class="org.hibernate.auction.Bid" usage="read-only"/>
<collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write"/>
</session-factory>
</hibernate-configuration>
這是完整的堆棧跟蹤,謝謝!
02:02:35.149 [main] DEBUG o.h.i.util.xml.DTDEntityResolver - Located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
Failed to create sessionFactory object.org.hibernate.MappingException: invalid configuration
Exception in thread "main" java.lang.ExceptionInInitializerError
at ProgettoPersonale.ProgettoPersonale.ManagePlayers.addPlayer(ManagePlayers.java:27)
at ProgettoPersonale.ProgettoPersonale.PlayersMain.main(PlayersMain.java:23)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2098)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2015)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1994)
at ProgettoPersonale.ProgettoPersonale.ManagePlayers.addPlayer(ManagePlayers.java:21)
... 1 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 36; columnNumber: 20; Il contenuto del tipo di elemento "session-factory" deve corrispondere a "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
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.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1994)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:879)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2973)
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.doConfigure(Configuration.java:2095)
... 4 more
謝謝!它解決了我的問題。 –
Plz將其標記爲答案 –