2012-01-07 92 views
0

我是新來的冬眠搜索,我剛開始使用互聯網「如何做」一個樣本搜索項目。每一件事情似乎罰款,只是當我嘗試運行項目時,我得到了休耕錯誤:休眠搜索cfg文件錯誤

Jan 7, 2012 4:10:41 PM org.hibernate.annotations.common.Version <clinit> 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} 
Jan 7, 2012 4:10:41 PM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.0.0.Final} 
Jan 7, 2012 4:10:41 PM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000206: hibernate.properties not found 
Jan 7, 2012 4:10:41 PM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
Jan 7, 2012 4:10:41 PM org.hibernate.cfg.Configuration configure 
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml 
Jan 7, 2012 4:10:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream 
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(4) Element type "hibernate-configuration" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(6) Element type "session-factory" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(11) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(13) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(16) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(17) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(18) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(21) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(25) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(27) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(31) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(32) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(34) Element type "property" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(36) Element type "listener" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(37) Element type "listener" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(38) Element type "listener" must be declared. 
Jan 7, 2012 4:10:41 PM org.hibernate.internal.util.xml.XMLHelper$ErrorLogger error 
ERROR: HHH000197: Error parsing XML: /hibernate.cfg.xml(40) Element type "mapping" must be declared. 

但我宣佈所有的錯誤,這是我cfg.xml文件:

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/"> 

<hibernate-configuration> 

    <session-factory> 

     <!-- 
     <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
     --> 
     <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 

     <property name="connection.url"> 
      jdbc:mysql://localhost:3306/hsearchexample 
     </property> 
     <property name="connection.username">root</property> 
     <property name="connection.password"></property> 
     <property name="connection.driver_class"> 
      com.mysql.jdbc.Driver 
     </property> 
     <property name="dialect"> 
      org.hibernate.dialect.MySQLDialect 
     </property> 

     <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property> 

     <property name="hibernate.search.default.indexBase"> 
      ./searchTMP/indexes 
     </property> 

     <property name="current_session_context_class">thread</property> 
     <property name="show_sql">true</property> 

     <property name="hbm2ddl.auto">create-drop</property> 

     <listener type="post-insert" class="org.hibernate.search.event.FullTextIndexEventListener"/> 
     <listener type="post-update" class="org.hibernate.search.event.FullTextIndexEventListener"/> 
     <listener type="post-delete" class="org.hibernate.search.event.FullTextIndexEventListener"/> 

     <mapping class="ir.ehphan.search.Article" /> 
    </session-factory> 
</hibernate-configuration> 

我不不知道該怎麼辦?我似乎沒有找到使用谷歌的答案...請幫助我。提前致謝。

回答

1

您使用的是hibernate 4,因此我們不應該在hibernate.cfg.xml中定義監聽器,而應該使用基於「服務發現」工作的org.hibernate.integrator.spi.Integrator,根據到Hibernate Core Migration Guide : 4.0。 ,你應該改變你的

1

根據dtd,它看起來應該有一個事件元素是你的會話工廠的子元素,並且在該事件元素中可以有偵聽器元素。