I have requirement in my application where we need to store index on the bases of user so I am trying to change location at runtime, but index is not getting stored on new location and if I am giving same location in config file then it is getting stored
I am using following code to change location
LocalSessionFactoryBean localSessionFactoryBean
localSessionFactoryBean.getConfiguration() .setProperty("hibernate.search.default.indexBase", "New_loc")
localSessionFactoryBean.getObject().getCurrentSession() //on this session object i am doing DAO opertation .
Rest configuration I have given in config file. I have invested my 3 days to find the solution for this but no success. Any help would be really appreciated. My code to get session is following
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();
}
and Bean is following
<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>
Update Code :
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();
}