-->
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.  [ 2 posts ] 
Author Message
 Post subject: Rebuilding index in Hibernate search throws exception
PostPosted: Fri May 02, 2008 4:55 pm 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
I have these code to rebuild an index. This code is copied from this forum almost verbatim:

Code:

        Transaction userTx = null;

        try {
            log.debug("deleting indexed documents");
            FullTextHibernateSessionProxy proxy = (FullTextHibernateSessionProxy) entityManager.getDelegate();
//            EntityManager em = entityManager;//(EntityManager) Component.getInstance("entityManager");
//            Session session = (Session) em.getDelegate();
            userTx = proxy.beginTransaction();
//            userTx.begin();

            // Delete all documents with "_hibernate_class" term of the selected entity
            DirectoryProvider dirProvider = proxy.getSearchFactory().getDirectoryProviders(entityClass)[0];
            IndexReader reader = IndexReader.open(dirProvider.getDirectory());

            // TODO: This is using an internal term of HSearch
            reader.deleteDocuments(new Term("_hibernate_class", entityClass.getName()));
            reader.close();

            // Optimize index
            log.debug("optimizing index (merging segments)");
            proxy.getSearchFactory().optimize(entityClass);

            userTx.commit();

            log.debug("indexing documents in batches of: " + batchSize);

            // Now re-index with HSearch
            proxy = (FullTextHibernateSessionProxy) entityManager.getDelegate();
            userTx = proxy.beginTransaction();
//            userTx.begin();

            // Use HQL instead of Criteria to eager fetch lazy properties
            ScrollableResults cursor = proxy
                    .createQuery("select o from " + entityClass.getName() + " o where status=:status")
                    .setParameter("status", Constants.Status.ACTIVE).scroll();
            cursor.last();
            int count = cursor.getRowNumber() + 1;  // rowNumber will be -1 if there is no row
            cursor.first(); // Reset to first result row
            int i = 0;
            while (true && count > 0) {
                i++;
                Object o = cursor.get(0);
                log.debug("indexing: " + i);
                proxy.index(o);
                if (i % batchSize == 0) proxy.clear(); // Clear persistence context for each batch

                if (cursor.isLast())
                    break;
                else
                    cursor.next();
            }
            cursor.close();
            userTx.commit();

            log.debug("indexing complete of entity class: " + entityClass);

        } catch (Exception ex) {
            try {
                if (userTx != null) userTx.rollback();
            } catch (Exception rbEx) {
                rbEx.printStackTrace();
            }
            throw new RuntimeException(ex);
        }


I am using Hibernate search 3.0.0 and Seam 2.0. The code works fine when I index about 10,000 records, but throws this error when I am indexing 100,000 records:

Quote:
2008-05-02 12:39:45,765 WARN [org.hibernate.jdbc.AbstractBatcher] exception clearing maxRows/queryTimeout
java.sql.SQLException: The statement is closed.
at org.jboss.resource.adapter.jdbc.WrappedStatement.checkState(WrappedStatement.java:599)

...

com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after statement closed.

...


How do I avoid that? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 7:16 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I assume that you index to many entities within one transaction. Have you set the flush mode to FlushMode.MANUAL. Otherwise proxy.clear() won't really help.

Also have a look at the manual indexing chapter oft the Hibernate Search documentation. It has an example of pretty much what you are trying to do - http://www.hibernate.org/hib_docs/search/reference/en/html_single/#search-batchindex-indexing.

--Hardy


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