Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: freeze on MassIndexer.startAndWait
PostPosted: Tue Jun 19, 2012 6:01 pm 
Newbie

Joined: Tue Jun 19, 2012 5:25 pm
Posts: 2
Hi,

I am struggling with freeze while executing MassIndexer.startAndWait:
Code:
[Hibernate Search: entityloader-1] DEBUG org.hibernate.loader.Loader - Result row: EntityKey[domain.Category#2], null, EntityKey[domain.Country#1], EntityKey[domain.Continent#1], null, EntityKey[domain.Page#1]

2012-06-19 23:38:59,885 [Hibernate Search: entityloader-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'domain.Country': PersistenceElement for transient javax.persistence.EntityManager domain.Country.entityManager


Page should be indexed. It contains @ManyToOne Country which contains @ManyToOne Continent. I use @IndexedEmbedded on country and continent members.

It appears that this error is connected with the fact that all domain objects have EntityManager injected in the following way (I have used Spring Roo to generate the initial code):

Code:
@PersistenceContext
transient EntityManager entityManager;

   public static final EntityManager entityManager() {
        EntityManager em = new Continent().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }


When I simply remove @PersistenceContext for tests, the project starts correctly.

MassIndexer is started in the service:
Code:
@Service
public class SearcherImpl {

   @PersistenceContext
   transient EntityManager entityManager;
   
   
   public SearcherImpl() {
   }
   
   @PostConstruct
   private void postConstruct() throws InterruptedException {
      FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
      fullTextEntityManager.createIndexer().threadsToLoadObjects(1).threadsForSubsequentFetching(1).batchSizeToLoadObjects(1).startAndWait();
   }
...}


I am using Hibernate 4.1.4.Final, Hibernate Search 4.1.1.Final, Spring 3.1.1.RELEASE, JPA, MySQL, Tomcat 7.

Does anyone know what might be wrong? Thanks for help in advance.


Top
 Profile  
 
 Post subject: Re: freeze on MassIndexer.startAndWait
PostPosted: Wed Jun 20, 2012 5:57 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2296
Location: Third rock from the Sun
Hi,
I've never seen it, but injecting the EntityManager in the domain object looks like a terrible idea.

If you can make a unit test so that I can reproduce it without having to learn Spring Roo, I'd be happy to look into it.

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


Top
 Profile  
 
 Post subject: Re: freeze on MassIndexer.startAndWait
PostPosted: Wed Jun 20, 2012 9:54 am 
Newbie

Joined: Tue Jun 19, 2012 5:25 pm
Posts: 2
I am still not sure what was wrong but after delaying instantiation of the service the project started to work. I simply removed
Code:
@Service
annotation and added
Code:
<bean class="service.impl.SearcherImpl"></bean>
to webmvc-config.xml. As a result, the service is created at the end and startAndWait finishes.


Top
 Profile  
 
 Post subject: Re: freeze on MassIndexer.startAndWait
PostPosted: Wed Jun 20, 2012 10:06 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2296
Location: Third rock from the Sun
I don't know exactly how your change helps, but I guess it was deadlocking on the amount of connections it opens.

I guess you have a connection pool to the database, and the MassIndexer uses a lot of connections to try loading as much data in parallel as possible; maybe your previous pattern was reserving some open connections.

Hibernate doesn't need to open connections eagerly, but common patterns with Spring force that practice. Technically the JDBC specification should allow me to use a single connection from multiple threads in parallel, but most drivers will break if I do :(

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.