我有需要在我的應用程序,我們需要存儲索引的基礎上的用戶,所以我試圖改變位置在運行時,但索引不獲取存儲在新的位置,如果我在配置文件中給出相同的位置,然後是我使用下面的代碼來改變位置當在運行時更改休眠索引位置(lucene)索引沒有獲取存儲在新位置
LocalSessionFactoryBean localSessionFactoryBean
localSessionFactoryBean.getConfiguration() .setProperty("hibernate.search.default.indexBase", "New_loc")
localSessionFactoryBean.getObject().getCurrentSession() //on this session object i am doing DAO opertation .
休息的配置我在配置文件中已經給獲得存儲
。我投入了3天的時間尋找解決方案,但沒有取得成功。任何幫助將非常感激。 我的代碼來獲取會話以下
protected Session getSession() {
Configuration conf=sessionFactory.getConfiguration();
conf.setProperty("hibernate.search.default.indexBase","c:\\testdata" /*CustomerContextHolder.getFile()!=null?CustomerContextHolder.getFile():defaultFileLocation*/);
ContextHolder.getOrBuildSearchFactory(conf);
return sessionFactory.getObject().getCurrentSession();
// sessionFactory.getObject().openSession();
}
和豆製品是繼
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <!-- Options are [validate, create, update, create-drop] -->
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<!-- Connection pool size -->
<prop key="hibernate.connection.pool_size">${hibernate.connection.pool_size}</prop>
issue -->
<prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.impl.FSDirectoryProvider</prop>
<prop key="hibernate.search.default.locking_strategy">single</prop>
<prop key="hibernate.search.default.indexBase">c:\abc</prop>
<prop key="hibernate.search.lucene_version">LUCENE_35</prop>
</props>
</property>
更新代碼:
Session getSession() {
Configuration conf=sessionFactory.getConfiguration();
conf.setProperty("hibernate.search.default.indexBase","c:\\testdata");
//conf.configure(); Need to commented otherwise shwoing duplicate Property
ServiceRegistry serviceRegistry= new ServiceRegistryBuilder().applySettings(
conf.getProperties()).buildServiceRegistry();
return (Session) conf.buildSessionFactory(serviceRegistry).openSession();
}
你有沒有試過調用'ContextHolder'的'getOrBuildSearchFactory'?例如'ContextHolder.getOrBuildSearchFactory(config)' – Amogh
在使用'setProperty'改變hibernate屬性之後,你必須重新構建sessionFactory。 – Amogh
感謝您的評論,所以我需要在localSessionFactoryBean.getObject()。getCurrentSession()和localSessionFactoryBean.getConfiguration().setProperty(「hibernate.search.default.indexBase」,「New_loc」)之前調用(getOrBuildSearchFactory)。它使交易問題becuasue我已經嘗試 斷開curent會話,然後嘗試使用openSession打開新seetio然後它給橫斷相關的錯誤 – user1047873