Hi,
I have the exact same problem:
- my persistence.xml is similar
Code:
<persistence-unit name="default" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/__default</jta-data-source>
<jar-file>lib/my-model.jar</jar-file>
<properties>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.cache.use_second_level_cache" value="false" />
</properties>
</persistence-unit>
- my index code is similar
Code:
import org.hibernate.CacheMode;
import org.hibernate.search.jpa.Search;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class IndexServiceBean implements IndexService {
@PersistenceContext(unitName = "default")
private EntityManager em;
@Override
public void index() {
try {
Search.getFullTextEntityManager(em)
.createIndexer(MyClass.class)
.batchSizeToLoadObjects(25)
.cacheMode(CacheMode.IGNORE)
.threadsToLoadObjects(5)
.threadsForSubsequentFetching(5)
.startAndWait();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
- I'm using glassfish v3.1b16 (I also tried on 3.1b11)
I'm using Hibernate Search 3.2.1.Final and yet, I have the same error:
Code:
[#|2010-08-25T11:58:07.091-0400|SEVERE|glassfish3.1|org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer|_ThreadID=472;_ThreadName=Hibernate Search: collectionsloader-2;|error during batch indexing:
org.hibernate.TransactionException: Could not register synchronization for container transaction
at org.hibernate.transaction.CMTTransaction.begin(CMTTransaction.java:76)
at org.hibernate.ejb.transaction.JoinableCMTTransaction.begin(JoinableCMTTransaction.java:89)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1463)
at org.hibernate.search.batchindexing.EntityConsumerLuceneworkProducer.run(EntityConsumerLuceneworkProducer.java:90)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
|#]
After debugging, it seems that the Search.getFullTextEntityManager(em) portion of the statement does create an entity manager whose transaction successfully joins the current one, but in the threads spawned by the indexer, the EntityConsumerLuceneworkProducer does a "session.beginTransaction()" and that's where it crashes. Did you have to do anything other than using the latest Hibernate Search version (3.2.1)?
Also, I'm confused about the following statement in the Hibernate Search documentation:
Quote:
The MassIndexer was designed for speed and is unaware of transactions, so there is no need to begin one or committing. Also because it is not transactional it is not recommended to let users use the system during it's processing, as it is unlikely people will be able to find results and the system load might be too high anyway.
I'm guessing they talk about the part where they manage the Lucene index because the part of the process that actually fetches the entities to index from the database does use a transaction (or at least, it appears each entity consumer thread is trying to create one).
Thank you very much.