-->
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.  [ 6 posts ] 
Author Message
 Post subject: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 2:43 am 
Newbie

Joined: Tue Jun 16, 2015 11:05 am
Posts: 4
I'm developing a Webapplication with Spring Boot and Spring Data Jpa with Hibernate. Due to the need of a full-text search capability I integrated the Hibernate Search Engine, but the Entities are not indexed unless I do a manual indexing by

fullTextEntityManager.createIndexer().startAndWait();

If I do the manual indexing of all Entities then everything works fine, but if I use the save()-Method of the CrudRepository then the index is not created.

Code:
public interface JobRepositoryCustom {
    public List<Job> searchJobs(SearchDto searchDto);
}


Code:
@Repository
public interface JobRepository extends  CrudRepository<Job, Integer>, JobRepositoryCustom {
}


Code:
public class JobRepositoryImpl implements JobRepositoryCustom {
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public List<Job> searchJobs(SearchDto searchDto) {
        List<Job> jobs;
        FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(entityManager);

        /*
        try {
            fullTextEntityManager.createIndexer().startAndWait();
        } catch (InterruptedException e) {
            System.out.println("An error occurred trying to build the serach index: " + e.toString());
        }*/

        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Job.class).get();

        org.apache.lucene.search.Query luceneQuery =   queryBuilder.bool().must(queryBuilder.keyword().onFields("title",  "introduction").matching(searchDto.getSearchTerm()).createQuery()).createQuery();

        org.hibernate.search.jpa.FullTextQuery fullTextQuery =    fullTextEntityManager.createFullTextQuery(luceneQuery, Job.class);

        jobs = fullTextQuery.getResultList();

        return jobs;
    }
}


I have searched the whole Internet for a solution and I appreciate every assistance. Thanks


Top
 Profile  
 
 Post subject: Re: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 5:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
You can only query the changes after the transaction was committed. Are you saving things within the same transaction which is performing the query?

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


Top
 Profile  
 
 Post subject: Re: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 10:59 am 
Newbie

Joined: Tue Jun 16, 2015 11:05 am
Posts: 4
sanne.grinovero wrote:
You can only query the changes after the transaction was committed. Are you saving things within the same transaction which is performing the query?


Hi, I'm not saving the entities within the same transaction which is performing the query. The entities are saved by a service layer class which is using a Crudrepository and invocating the save method on it. Crudrepo methods are transactional by default in spring data jpa.


Top
 Profile  
 
 Post subject: Re: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 11:13 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Ok, I tried to guess with the most common misunderstandings I've seen for such a problem.

Another thing I would suggest to verify is to see if your transaction manager is configured correctly: that's another common problem with Spring users. Or simply debug it and try to see why the indexing events are not being applied.

I'm sorry I don't have other ideas, but I'm pretty sure this is just configuration issue.

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


Top
 Profile  
 
 Post subject: Re: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 2:38 pm 
Newbie

Joined: Tue Jun 16, 2015 11:05 am
Posts: 4
Spring-Data-Jpa is doing the transaction management by default and automatically. I don't exactly know what to configure at the transaction manager. How to debug it?


Top
 Profile  
 
 Post subject: Re: Spring-Data-Jpa + Hibernate-Search - Index not created
PostPosted: Wed Jun 17, 2015 3:49 pm 
Newbie

Joined: Tue Jun 16, 2015 11:05 am
Posts: 4
Hi,

I've solved the problem. I'm using an h2 database which stores the data in a file after the application is stopped and I forgot to cleanup the database files.


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