首页 | 网站地图 | RSS订阅 | 高级搜索 | 收藏本站
默认搜索       热门关键字: lucene  nutch  eee  sdD  dad
Google广告位置
Google AD
当前位置:搜索引擎>Lucene> 正文

  • Lucene+hibernate+spring配置心得
  • 日期:2007-09-23   点击:   作者:蒋萌   来源:http://blog.csdn.net/cheny424242/archive/2007/09/2   字体:[ ]

需要准备的包:

hibernate3.2.0.jar

hibernate-annotations.jar

ejb3-persistence.jar

lucene-core-2.0.0.jar

spring1.2.6.jar
基本上值得注意的包就这些了,如果你有用ehcache做hibernate的cache,那么你需要
使用ehcache-1.2.1版本的jar包。
ejb3-persistence.jar包可以在hibernate-annotations的下载包中找到

关于hibernate的配置:
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd
">
<hibernate-configuration>
 <session-factory name="sessionFactory">
  <property name="
hibernate.lucene.index_dir
">\indexDir</property>
  <property     name="
hibernate.lucene.analyzer
">org.apache.lucene.analysis.standard.StandardAnalyzer</property>
  <event type="
post-commit-update
">
   <listener class="org.hibernate.lucene.event.LuceneEventListener"/>
  </event>
  <event type="
post-commit-insert
">
   <listener  class="org.hibernate.lucene.event.LuceneEventListener"/>
  </event>
  <event type="
post-commit-delete
" >
   <listener class="org.hibernate.lucene.event.LuceneEventListener"/>
  </event>
 </session-factory>
 
</hibernate-configuration>
hibernate.lucene.analyzer
这是为lucene指定一个分词器
这两项不是必须配置的,但是配置了以后,省去许多麻烦
post-commit-update,post-commit-insert,post-commit-delete
为hibernate这3种状态指定监听器。hibernate正是透过这3个状态的监听,来更新lucene索引的
  hibernate.lucene.index_dir:
这是为lucene指定一个index目录(可以给绝对路径,因为我是linux系统,所以没有盘符),当然仅对hibernate有效,如果你跳过hibernate直接操作
lucene,这个目录是没有用的

Spring下的配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource"><ref local="dataSource"/></property>
  <property name="mappingResources">
    <list>
    <value>FaqMessage.hbm.xml</value>
   </list>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
    <prop key="hibernate.connection.release_mode">on_close</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.connection.autocommit">false</prop>
   </props>
  </property>
 
 <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"/>
  <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
  
 </bean>
熟悉spring+hibernate的人应该都对这个配置不陌生,值得注意的是最后两项,一定要配。


共2页: 上一页 1 [2] 下一页
所有评论 关闭窗口↓ 打印本页 论坛讨论 返回列表
用户名: 新注册) 密码: 匿名评论 [所有评论]

评论内容:(不能超过250字,请自觉遵守互联网相关政策法规。

最新评论: