Hi,
I'm using Hibernate Search (hibernate-search-4.1.0.CR3) with JPA and JBOSS AS 7.1.2.
So my configuration is classic:
=> In persistence.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence ...
<persistence-unit name="PUNAME">
<jta-data-source>java:jboss/datasources/PUNAME_DS</jta-data-source>
<class>...</class>
<class>...</class>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
...
<!-- Configuration for Hibernate Search -->
<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.impl.FSDirectoryProvider"/>
<property name="hibernate.search.model_mapping" value="fr....modele.search.XXXSearchMappingFactory" />
<!-- Contient les propriétés dépendantes de l'environnement -->
<property name="hibernate.ejb.cfgfile" value="/indexesConfiguration/hibernate.cfg.xml" />
</properties>
</persistence-unit>
</persistence>
=> In /indexesConfiguration/hibernate.cfg.xml:
Code:
<hibernate-configuration>
<session-factory>
<property name="hibernate.search.default.indexBase">d:/.../temp/lucene/indexes</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>
=> In JBOSS standalone.xml, there is a module declaration in order to put hibernate.cfg.xml in the classpath:
Code:
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<global-modules>
<module name="fr.xxx" slot="main"/>
</global-modules>
</subsystem>
And so the hibernate.cfg.xml is in the path ...\jboss-as-7.1.2.Final\modules\fr\xxx\main\indexesConfiguration
=> I have a class fr....modele.search.XXXSearchMappingFactory with getSearchMapping() method with "Factory" annotation.
=> When the application start,i have a singleton wich execute "createIndexer":
Code:
@ApplicationScoped
@Singleton
@Startup
public class XXX {
@PostConstruct
public void startUp() {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
Class<?> entities = getIndexedEntities();
try {
logger.info("Going to reindex entities: {}", entities);
long start = System.currentTimeMillis();
fullTextEntityManager.createIndexer(entities)
.purgeAllOnStart(true)
.batchSizeToLoadObjects(25)
.cacheMode(CacheMode.IGNORE)
.threadsToLoadObjects(5)
.idFetchSize(150)
.threadsForSubsequentFetching(20)
.progressMonitor(new SimpleIndexingProgressMonitor()) // a MassIndexerProgressMonitor implementation
.startAndWait();
long end = System.currentTimeMillis();
logger.info("Reindex ended in : {} ms", (end-start));
} catch (InterruptedException e) {
logger.error("Can't create index for entities: {}", entities, e);
}
}
}
It works fine but i want to externalize the property "hibernate.ejb.cfgfile" and set this property by using an env variable: -Duser.conf=d:/.../hibernate.cfg.xml or even -Dhibernate.search.default.indexBase=d:/.../temp/lucene/indexes.
<property name="hibernate.ejb.cfgfile" value="${user.conf}" /> don't work ... (exception org.hibernate.HibernateException: ${user.conf} not found)
Is there a way to do this ?
thx