I have a requirement in my application where we need to store the index based on the user, so I try to change the location at runtime, but the index is not saved in the new location, and if I provide the same location in the configuration file, it gets saved
I use the 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 .
The break configuration specified in the configuration file. I spent 3 days finding a solution for this, but without success. Any help could be helpful. My session code is as follows
protected Session getSession() {
Configuration conf=sessionFactory.getConfiguration();
conf.setProperty("hibernate.search.default.indexBase","c:\\testdata" );
ContextHolder.getOrBuildSearchFactory(conf);
return sessionFactory.getObject().getCurrentSession();
}
and bean follows
<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>
<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");
ServiceRegistry serviceRegistry= new ServiceRegistryBuilder().applySettings(
conf.getProperties()).buildServiceRegistry();
return (Session) conf.buildSessionFactory(serviceRegistry).openSession();
}