-->
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.  [ 9 posts ] 
Author Message
 Post subject: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Wed Jul 08, 2009 10:17 am 
Hello *,

the situation is as follows. When i start the application, the index folders get created. If i place wrong Search Annotations i get errors, so this part seems to be okay.

But when i start the indexing process i don't get errors, but although the entities don't get indexed.
Even other Transactions are handled without errors and work properly, only indexing fails.

I found these, but don't get it:

https://forum.hibernate.org/viewtopic.php?f=9&t=996131&hilit=index+entity+spring
http://forum.springsource.org/showthread.php?t=67651
https://www.hibernate.org/441.html

I would be glad if some of you have a look on the configuration files and give me a hint how to solve this.

Thx

**********

    hibernate-search 3.1.0.GA
    hibernate-core 3.3.1.GA
    lucene-core 2.4.1
    hibernate-commons-annotations 3.0.0.GA
    solr-common 1.3.0
    solr-core 1.3.0
    apache-solr-analyzer 1.2.0
    org.springframework.core 2.5.6.A
    org.springframework.webflow 2.0.7.RELEASE
    etc.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

   <!-- DATA SOURCE DEFINITION [oracle] -->

   <bean id="dataSourceTarget" autowire-candidate="false"
      class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName" value="jdbc/XXX" />
      <property name="resourceRef" value="true" />
   </bean>

   <bean id="userContextAwareDataSourceProxy" 
                                                                <!-- entends org.springframework.jdbc.datasource.DelegatingDataSource-->
      class="XXX.common.spring.jdbc.UserContextAwareDataSourceProxy"
      autowire-candidate="false">
      <property name="targetDataSource" ref="dataSourceTarget" />
      <property name="contextAware">
         <bean class="XXX.common.spring.jdbc.SpringSecurityUserContext" />
      </property>
      <property name="userContextDAO">
         <bean class="XXX.common.spring.jdbc.FUserContextDAO" />
      </property>
   </bean>

   
   <!-- Context aktiviert -->
   <bean id="dataSource"
      class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
      <property name="targetDataSource" ref="userContextAwareDataSourceProxy" />
   </bean>

   <!-- Hibernate Session-Factory -->
   <bean id="sessionFactory"
      class="XXX.common.spring.hib.ContextAwareSessionFactoryBean" <!--
      depends-on="dataSource">

      <property name="initContextAware">
         <bean class="XXX.common.spring.jdbc.SimpleSecurityUserContext">
            <property name="userName" value="INIT" />
         </bean>
      </property>

      <property name="useTransactionAwareDataSource" value="true" />

      <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />

      <property name="configLocations">
         <list>
            <!--
               <value>classpath:*-hibernate.cfg.xml</value>
               <value>classpath*:META-INF/hib-common-hibernate-dao.cfg.xml</value>
            -->
            <value>classpath*:META-INF/hib-*.cfg.xml</value>
         </list>
      </property>

      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.session_factory_name">null</prop>
            <prop key="hibernate.format_sql">true</prop>
         </props>
      </property>
      <property name="dataSource" ref="dataSource" />
   </bean>

   <!-- a PlatformTransactionManager is still required -->
   <bean id="transactionManager"
      class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource">
         <ref bean="dataSource" />
      </property>
   </bean>

   <tx:annotation-driven transaction-manager="transactionManager" />

</beans>


Code:
public class ManualIndexerDao {
   ...
   public void indexEntityList(List<Object> list) {
      Session session = getSessionFactory().getCurrentSession();
      FullTextSession fullTextSession = Search
            .getFullTextSession(session);
      fullTextSession.setFlushMode(FlushMode.MANUAL);
      fullTextSession.setCacheMode(CacheMode.IGNORE);
      for (Object entity : list) {
         fullTextSession.index(entity);
      }
      fullTextSession.flushToIndexes();
      fullTextSession.clear();
   }
}


Code:
public class ManualIndexerSvc {

   private ManualIndexerDao dao;

   private int batchSize = 1000;
   
   
   @Transactional
   public void indexAll(Class clazz) {

      int anzahlZeilen = dao.getAllRowsCount(clazz);
               
                int index = 0;
      while (index < anzahlZeilen) {
                  
         List<Object> list = dao.findAll(clazz, null, index, batchSize);
                                                  //returns db rows from index to index+batchSize

         dao.indexEntityList(list);
         
         index += batchSize;
      }
   }
}


Code:
@Indexed
public class Test extends Serializable{
       
        public static final String PROPERTY_ID = "id";

     
        @GeneratedValue(generator="id")
   @Id   
   protected Long id;
 

   @Column
        @Field
   private String test;


Last edited by byte on Thu Jul 09, 2009 4:09 am, edited 2 times in total.

Top
  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Wed Jul 08, 2009 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
does your Test entity have an @Id of @DocumentId ?
How do you know the index is not being made, did you look into it with Luke ?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Thu Jul 09, 2009 4:05 am 
Hello Sanne,

thanks for your reply.

Sorry for the incomplete sample CodeListing. Yes, there is an @Id Annotation at the id.
( I 'll change the code in the first post immediately)

Yes, I looked at the index with luke, got the error code 0 which stands i think for an empty index, cause Lukes analyzer function told me, that the index is not broken.

There are two files in the folder, 20 Byte and 28 Byte, like in the first post i pointed to.

Greetings Matthias


Last edited by byte on Thu Jul 09, 2009 5:10 am, edited 1 time in total.

Top
  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Thu Jul 09, 2009 4:55 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
Yes, I looked at the index with luke, got the error code 0 which stands i think for an empty index, cause Lukes analyzer function told me, that the index is not broken.

There are two files in the folder, 20KB and 28KB, like in the first post i pointed to.


That size doesn't look like an empty index, it should be much smaller; I'm not getting error code 0 on an empty index anyway...
using Luke, could you look into the first page (index overview) and see how many documents and terms there are in the index.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Thu Jul 09, 2009 5:28 am 
Sorry its 20 Byte and 28 Byte not KB, my fault.
These files are created during the start of the webapp, before i start the manual indexing.

I use the luke-0.9.2.jar to look at the index. I get an "Index succesfully open" at the normal gui and an error popup window.

The "check index tool" of luke says:
    Segments file=segments_1 numSegments=0 version=FORMAT_HAS_PROX [Lucene 2.4]
    No problems were detected with this index.

I cannot find anything about the error code 0 of Luke but i think that doesnt really matter.

The guy at this post https://forum.hibernate.org/viewtopic.php?f=9&t=996131&hilit=index+entity+spring had the same problem. (same file size, no entities indexed)

**********
Update

I don't know why, but after experimenting a little bit it works with the above configuration now. If i am able to say what caused this behavior i'll post it here.

Nevertheless, thank you very much for breeding over my problem
**********


Top
  
 
 Post subject: Manual Indexing is running, automatic indexing not
PostPosted: Fri Jul 10, 2009 6:16 am 
As i said manual indexing is running now.

Certainly automatic indexing does not work.
I added the EventListeners like i read in "Hibernate Search in Action" page 140, but the changes i make in the application are only passed through to the DataBase, not to the Index.

Code:
<!-- Hibernate Session-Factory -->
   <bean id="sessionFactory"
      class="XXX.common.spring.hib.ContextAwareSessionFactoryBean"
      depends-on="dataSource">                                  <!-- extends LocalSessionFactory -->

      <property name="initContextAware">
         <bean class="XXX.common.spring.jdbc.SimpleSecurityUserContext">
            <property name="userName" value="INIT" />
         </bean>
      </property>

      <property name="useTransactionAwareDataSource" value="true" />

      <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />

      <property name="configLocations">
         <list>
            <value>classpath*:META-INF/hib-*.cfg.xml
            </value>
         </list>
      </property>

      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.search.default.indexBase">Lucene_Index
            </prop>
            <prop key="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider
            </prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
            </prop>
            <prop key="hibernate.search.autoregister_listeners">true</prop>
            <prop key="hibernate.session_factory_name">null</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.show_sql">false</prop>
         </props>
      </property>
      
      <property name="eventListeners">
         <map>
            <entry key="post-update">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
            <entry key="post-insert">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
            <entry key="post-delete">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
            <entry key="post-collection-recreate">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
            <entry key="post-collection-remove">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
            <entry key="post-collection-update">
                  <bean class="org.hibernate.search.event.FullTextIndexEventListener" />
            </entry>
         </map>
      </property>

      <property name="dataSource" ref="dataSource" />

   </bean>


Top
  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Fri Jul 10, 2009 8:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you tried using a different transaction manager - JTATransactionManager or HiberntateTransactionManager?

--Hardy


Top
 Profile  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Fri Jul 10, 2009 8:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Another note - I am not really an expert, but I think the problem is that the transaction manager in the case of Hibernate has to be synced on the SessionFactory. The DataSourceTransactionManager, however, syncs on the data source. It might be worth to read through the Spring transaction management configuration - http://static.springsource.org/spring/d ... ction.html

--Hardy


Top
 Profile  
 
 Post subject: Re: Spring, TransactionManager?, Entities don't get indexed
PostPosted: Mon Jul 13, 2009 4:00 am 
Hello Hardy,

thanks for your quick reply. I tried the JTATransactionManager with the result that the manual indexing worked but the rest of the application did not. With HibernateTransactionManager everything seems to work fine now. Thank you very much.

Matthias


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.