-->
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 seems not work with spring batch.
PostPosted: Wed May 13, 2015 11:07 am 
Newbie

Joined: Tue May 12, 2015 9:04 am
Posts: 2
Hello

I have a web project with spring, hibernate,... and now I am using Hibernate search integrated with this project that works fine. The problem is that I have a restriction to save processing, that every search I have to save and a process running in another project, spring batch will perform the search using hibernate search, when I run a search in the main project (web) hibernate search works fine, but in the other project with spring batch not. The same search that find results in the web project doesn't find nothing in the spring batch process.

The project spring batch is a Maven project has in the pom.xml a dependency of the web project, to bring the classes to search using hibernate search, in the web project I updated to the new version of Hibernate Search 5.2.0.Final, because I'm using multi-tenancy too.

Follow a snippet code of my applicationContext of the web project that all works, the bean entityManagerFactory:

Code:
<bean depends-on="dataSource" id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="showSql" value="true" />
         </bean>
      </property>
      <property name="packagesToScan" value="xx.xxx.xxxxxx.xx" />
      <property name="persistenceUnitName" value="XXXToolsJPA" />
      <property name="dataSource" ref="dataSource" />
      <property name="jpaProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            <prop key="hibernate.multiTenancy">DATABASE</prop>
            <prop key="hibernate.tenant_identifier_resolver">xx.xxxx.xxxxxx.SchemaResolver</prop>
            <prop key="hibernate.multi_tenant_connection_provider">xx.xxxx.xxxxxx..MultiTenantProvider</prop>
            <prop key="hibernate.search.default.directory_provider">filesystem</prop>
            <prop key="hibernate.search.default.indexBase">C:\xxx\indexes</prop>
         </props>
      </property>
   </bean>


Now the snippet of applicationContext in the spring batch project, that isn't working:


Code:
<bean depends-on="dataSource" id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="jpaVendorAdapter">
         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="databasePlatform" value="org.hibernate.dialect.SQLServerDialect" />
            <property name="showSql" value="true" />
         </bean>
      </property>
      <property name="packagesToScan" value="xx.xxx.xxxxxx.xx" />
      <property name="persistenceUnitName" value="XXXToolsJPA" />
      <property name="dataSource" ref="dataSource" />
      <property name="jpaProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
            <prop key="hibernate.multiTenancy">DATABASE</prop>
            <prop key="hibernate.tenant_identifier_resolver">xx.xxx.xxxxxx.xx.SchemaResolverProcessos</prop>
            <prop key="hibernate.multi_tenant_connection_provider">xx.xxx.xxxxxx.xx.MultiTenantProviderProcessos</prop>
            <prop key="hibernate.search.default.directory_provider">filesystem</prop>
            <prop key="hibernate.search.default.indexBase">C:\suse\indexes</prop>
         </props>
      </property>
   </bean>


The entityManagerFactory are equal, and that I implemented the search is the same used in the web project and the spring batch project.
Other thing is that Hibernate search doesn't work with Junit.

Any suggestion?


Top
 Profile  
 
 Post subject: Re: Hibernate search seems not work with spring batch.
PostPosted: Thu May 14, 2015 4:45 pm 
Newbie

Joined: Tue May 12, 2015 9:04 am
Posts: 2
Hello

Problem solved !!!

Reading the documentation of hibernate Search (3.3. Directory configuration), I found the option to use shared index, this save me.

The solutions was:

On each entity with anotation with @Indexed, I added a name to the index like @Indexed(index="newIndex"),

on my applicationContext of each project the bean entityManagerFactory I changed the properties

Code:
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">C:\xxx\indexes</prop>


to

Code:
<prop key="hibernate.search.newIndex.directory_provider">filesystem</prop>
<prop key="hibernate.search.newIndex.indexBase">C:\xxx\indexes</prop>


Now each project will seach on the same index.

I don't know if this is the best solution, but works fine.


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.