-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Search externalize hibernate.ejb.cfgfile property
PostPosted: Tue Jul 23, 2013 10:48 am 
Newbie

Joined: Tue Jul 23, 2013 8:24 am
Posts: 2
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


Last edited by jlebiannic on Mon Jul 29, 2013 3:40 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Search externalize hibernate.ejb.cfgfile property
PostPosted: Mon Jul 29, 2013 3:33 am 
Newbie

Joined: Tue Jul 23, 2013 8:24 am
Posts: 2
thanks for your answer but i want to externalize these properties as environment variables.

It isn't possible to do that ?:
-DindexBase=d:\...\xxx

and

<property name="hibernate.search.default.indexBase">${indexBase}</property>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.