-->
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: merge not updating lucene index
PostPosted: Fri May 13, 2011 6:00 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
Hi!

We have an index working with entitymanager persist method adding object to the index but entitymanager merge method is not updating the index.

Both methods use @Transactional and we have

Code:
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

as transactionmanager. I read that it might be an issue with transactionmanager. Is this true?

We are indexing a method on the object not a field. The method combines different text based on language.

Some versions:
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-entitymanager-3.6.3.Final.jar
lucene-core-3.1.0.jar
hibernate-core-3.6.3.Final.jar
hibernate-search-3.4.0.Final.jar

Any help is appreciated.


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Sun May 15, 2011 10:38 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
could you show the code? merge works fine normally.

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


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Mon May 16, 2011 2:31 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
Here's some code:

Code:
@Transactional(readOnly = true)
public class GeneralDaoImpl<ObjectType> extends JpaDaoSupport
        implements IGeneralDao<ObjectType> {
    @Override
    @Transactional
    public void create(ObjectType element) {
        getJpaTemplate().persist(element); // adds to lucene index
    }

    @Override
    @Transactional
    public void update(ObjectType element) {
        getJpaTemplate().merge(element); // doesn't update lucene index
    }
...
}

@Entity
@Table(name = "ad")
@SequenceGenerator(name = "ad_id_seq", sequenceName = "ad_id_seq", allocationSize = 1)
@Indexed(index = "AdIndex")
public class Ad {

    @OneToMany(mappedBy = "ad", cascade = CascadeType.ALL)
    private List<AdInfo> adInfos;

    @Field(index=Index.TOKENIZED, store=Store.NO)
    public String getSearchableInfo(){
       // returns info from adInfos objects
    }
   
}


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 4:39 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
Im ready to provide more data if somebody can point to the areas where my problem might be. I have been given the task to try to get hibernate search working.

Here's some more code samples.

Persistence.xml
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="managerJpa" transaction-type="RESOURCE_LOCAL"/>
    <property name="hibernate.search.default.directory_provider"
          value="org.hibernate.search.store.FSDirectoryProvider"/>
   
</persistence>


Datasource:
Code:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.username}" />
        <property name="password" value="${database.password}" />
        <property name="validationQuery" value="select now()" />
        <property name="maxActive" value="60" />
        <property name="initialSize" value="5" />
        <property name="maxWait" value="30000" />
    </bean>


EntityManager:
Code:
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceXmlLocation" value="classpath:persistence.xml" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false" />
                <property name="generateDdl" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" />
            </bean>
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.default_batch_fetch_size">100</prop>
            </props>
        </property>
    </bean>


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 5:09 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
so when the merge operation is invoked, is the database updated at that same point?
could you add some logging to your update method and enable SQL logging to verify that?
Also it could be useful to set the Hibernate Search log level to debug, or trace.

I'm suggesting this as I'm not a Spring expert and as you asked in the first post, yes often the problem is with the transactions configuration. Other times people use merge() inappropriately; personally I don't like the idea to change detached entities and re-attach them to a transaction after the fact.

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


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 8:06 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
s.grinovero wrote:
so when the merge operation is invoked, is the database updated at that same point?
could you add some logging to your update method and enable SQL logging to verify that?
Also it could be useful to set the Hibernate Search log level to debug, or trace.


No the database does not get updated at that same point. The service method that calls merge is @Transactional and it does some more things and things get commited after that method.


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 8:23 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
No the database does not get updated at that same point. The service method that calls merge is @Transactional and it does some more things and things get commited after that method.

Yes sorry bad wording. I meant to ask if you could check if the database changes would be properly flushed on return from the @Transactional method, not exactly during the merge. Hibernate Search should receive the event during the merge, but write to the index during the transaction commit.

So logs should be useful to check if Hibernate Search is receiving the update event, and also to check if the transaction is actually being committed (to verify your transactions configuration).
If the event is being received, and the transaction is properly committed, then from the logs we should see activity too from Hibernate Search pushing the changes to the indexing backend.

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


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 8:30 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
The service method that calls merge is @Transactional and it does some more things and things get commited after that method.

Another question: what is the transaction propagation? Remember that the index is updated only at commit time,so if you're checking the index state in the same transaction you won't find the to-be-stored new values yet.
You'll have to commit first, or use
Code:
org.hibernate.search.FullTextSession.flushToIndexes()

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


Top
 Profile  
 
 Post subject: Re: merge not updating lucene index
PostPosted: Fri Aug 26, 2011 9:45 am 
Newbie

Joined: Sat Jan 26, 2008 7:26 am
Posts: 10
I can't explain it but merge and delete are now updating index. Im pretty sure I tested it again this morning and it was not working. I can't understand what happened as I didn't change much but added some more fields to lucene index. I added Ad.modified to the index. Maybe that was something that forced updates.


Top
 Profile  
 
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.