我是hibernate搜索的新手,我刚刚开始使用互联网“how-to s”制作一个示例搜索项目。除了当我尝试运行项目时,我遇到了一些错误:
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>
我不知道该怎么办?我似乎没有使用谷歌找到答案...请帮助我。提前致谢。
答案 0 :(得分:1)
根据dtd,看起来应该有一个event元素是你的session-factory的子元素,并且在那个event元素中你可以有监听器元素。
答案 1 :(得分:1)
你正在使用hibernate 4,因此我们不应该在hibernate.cfg.xml中定义你的监听器,而应该使用一个基于“服务发现”的org.hibernate.integrator.spi.Integrator,根据Hibernate Core Migration Guide : 4.0。 你应该改变你的