Ok, just like I thought, everything is working now!
It apparently takes about 100mn to index my 3,000,000 Entities.
So christian, I tryed your routine like I promessed.
I have two problems with your algorithm.
First, the UserTransaction thing doesn't work.
Code:
userTx = (UserTransaction)org.jboss.seam.Component.getInstance("org.jboss.seam.transaction.transaction");
userTx.begin();
Apparently userTx is null, so I have a Java null pointer exception on the 'begin' line.
So instead, I used that code:
Code:
EntityManager em = (EntityManager) Component.getInstance("entityManager");
Session session = (Session) em.getDelegate();
tx = session.getTransaction();
tx.begin();
With that transaction, it works.
Second problem, the database query line.
With my 3,000,000 records, it simply throws a java heap out of memory error. It's apparently impossible (at least on my computer) to retrieve the whole records. So I had the divide it into several queries (with setFirstResult and setMaximumResult).
With both these changes, it works fine.
There's just an improvement that seems to work with me.
I replace this code:
Code:
ScrollableResults cursor = session.createQuery("select o from Book o fetch all properties").setFirstResult(firstID).setMaxResults(50000).scroll();
By this one:
Code:
ScrollableResults cursor = ftSession.createCriteria( Book.class ).setFirstResult(firstID).setMaxResults(50000).scroll();
Don't know why, but it seems to be about twice faster with the last one to index 10000 books (it's my batch_size).
One last question though.
If I want to improve the indexing performance, I guess I should first maximize the amount of items retrieved at a time, but what should I tweak then? Should I increase or decrease batch_size? Is there anything else I should change?