-->
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.  [ 1 post ] 
Author Message
 Post subject: hibernate-search - persistence.xml
PostPosted: Wed Mar 18, 2015 8:53 am 
Newbie

Joined: Wed Feb 11, 2015 9:28 pm
Posts: 2
Hi All, I am using hibernate with Spring.. For next requirement i have started using hibernate-search. I have added below properties to my persistence.xml and its working fine ..

Code:
<property name="hibernate.search.default.directory_provider" value="filesystem" />
<property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />


But, i want to provide indexBase from property file instead of hard coding same in persistence.xml file .. Below is my full persistence.xml file ..

Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="appPersistenceUnit"
                      transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:jboss/datasources/AppDS</jta-data-source>
        <class>com.app.domain.User</class>
        <!-- Other entity classes -->
        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>

            <property name="jboss.entity.manager.factory.jndi.name"
                      value="persistence-units/appPersistenceUnit"/>

            <property name="hibernate.transaction.jta.platform"
                      value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>

            <!-- Disable transaction auto commit (production) -->
            <property name="hibernate.connection.autocommit" value="false"/>

            <!-- Default character set -->
            <property name="hibernate.connection.charSet" value="UTF-8"/>

            <!-- Enable Hibernate's automatic session context management -->
            <property name="hibernate.current_session_context_class"
                      value="jta"/>

            <!-- SQL dialect -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

            <!-- Naming strategy -->
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>

            <!-- Format SQL outpout -->
            <property name="hibernate.format_sql" value="false"/>

            <!-- Enabling Statistics -->
            <property name="hibernate.generate_statistics" value="false"/>

            <!-- value="create" to build a new database on each run; value="update"
                to modify an existing database; value="create-drop" means the same as "create"
                but also drops tables when Hibernate closes; value="validate" makes no changes
                to the database -->
            <property name="hibernate.hbm2ddl.auto" value="validate"/>

            <!-- Enable batch procession using an integer between 10-50 -->
            <property name="hibernate.jdbc.batch_size" value="40"/>

            <!-- Echo all executed SQL to stdout -->
            <property name="hibernate.show_sql" value="false"/>

            <!-- Envers -->
            <property name="org.hibernate.envers.audit_strategy"
                      value="org.hibernate.envers.strategy.ValidityAuditStrategy"/>
            <property
                    name="org.hibernate.envers.audit_strategy_validity_end_rev_field_name"
                    value="revision_end"/>
            <property
                    name="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp"
                    value="true"/>
            <property
                    name="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name"
                    value="revision_end_time"/>
            <property name="org.hibernate.envers.audit_table_suffix" value="_aud"/>
            <property name="org.hibernate.envers.revision_field_name" value="revision"/>
            <property name="org.hibernate.envers.revision_type_field_name" value="revision_type"/>
            <property name="org.hibernate.envers.revision_listener"
                      value="com.app.listener.revision.RevisionListenerImpl"/>

            <!-- Infinispan -->
            <!-- Enables the query cache. You still need to set individual queries
                to be cacheable. Call org.hibernate.Query.setCacheable(true) to initiate. -->
            <property name="hibernate.cache.use_query_cache" value="true"/>
            <!-- Enable second level cache. Requires session flushing. -->
            <property name="hibernate.cache.use_second_level_cache" value="true"/>

            <!-- Hibernate Search properties -->
            <property name="hibernate.search.default.directory_provider" value="filesystem" />
            <property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />


        </properties>
    </persistence-unit>
</persistence>


I tried adding this property in my spring configuration file, but it's not working for me .. As you can see in my below spring context file that i have tried with code in comment.. where i am creating <bean id='entityManagerFactory' .... > and i am specifying indexBase path in there .. but this configuration is not working ..


Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd">

    <jee:jndi-lookup id="dataSource" expected-type="javax.sql.DataSource"
                     jndi-name="java:jboss/datasources/AppDS"/>

   <jee:jndi-lookup id="entityManagerFactory"
                     expected-type="javax.persistence.EntityManagerFactory"
                     jndi-name="java:comp/env/persistence/appPersistenceUnit"/>

   <!-------------------------
   
   <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.search.default.indexBase">/var/lucene/indexes</prop>
            </props>
        </property>
   </bean>   
   
   -->
    <bean id="transactionManager"
          class="org.springframework.transaction.jta.JtaTransactionManager"/>

    <bean id="entityManager"
          class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <bean id="exceptionTranslator"
          class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

</beans>



same question i have added in stack overflow as well .. at http://stackoverflow.com/questions/29065745/persistence-xml-property-values-from-properties-file

Request you to send your inputs ..

Thanks.


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

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.