-->
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.  [ 1 post ] 
Author Message
 Post subject: Problems reindexing using session.createCriteria(...)
PostPosted: Mon May 02, 2011 1:56 pm 
Newbie

Joined: Mon May 02, 2011 1:44 pm
Posts: 1
Hello all,

I am sort of a Hibernate noob, having inherited a project and have been reading and able to follow along. I have also been reading the documentation, so please point me if this is an obvious thing.

I notice that this code has a strange "bug" that occurs when doing a reindex. What I am seeing is that my table (whose name is group) has 908 rows. When I reindex, then search in my code for all groups, there are about 100 groups that do not come up in the search. We found this by accident, and I compared row by row against the search results and a select * from the group table.

So I ran the debugger against the indexing code and when the results list is created, there are rows in the group table that are NOT in the results List. How can this be? What would cause most group rows to be in the list, but not all?

Here is my code:

public int indexSet(final Class classToIndex, final int start, final int count, final int total, final TaskStatus status)
{
getHibernateTemplate().setExposeNativeSession(true);
Integer indexed = (Integer) getHibernateTemplate().execute(new HibernateCallback()
{
public Object doInHibernate(Session session) throws HibernateException, SQLException
{
int indexed = 0;
session.setCacheMode(CacheMode.IGNORE);
session.setFlushMode(FlushMode.COMMIT);

FullTextSession fullTextSession = Search.getFullTextSession(session);
Criteria criteria = session.createCriteria(classToIndex);

criteria.setMaxResults(count);
criteria.setFirstResult(start);
List results = criteria.list();

for (Object obj : results)
{
try
{
fullTextSession.index(obj);
indexed++;
status.setStatus("Indexed " + (indexed + start) + " of " + total + " of " + classToIndex.getSimpleName() + " entities..");
}
catch (Exception e)
{
Logger.getLogger(FtsIndexBean.class.toString()).log(Level.WARNING, "Exception indexing " + classToIndex + " object id " + indexed, e);
}
}
Logger.getLogger(FtsIndexBean.class.toString()).log(Level.INFO, "FTS Indexed " + (start + indexed) + " of " + total + " " + classToIndex + " entities..");
if (session != null)
{
try
{
fullTextSession.flush();
fullTextSession.flushToIndexes();
fullTextSession.clear();

System.gc();
}
catch (Exception ex)
{
Logger.getLogger(FtsIndexBean.class.toString()).log(Level.WARNING, "Exception re-opening session for " + classToIndex, ex);
}
}
return indexed;
}
});
getHibernateTemplate().setExposeNativeSession(false);
return indexed;
}

What else should I attach in order to provide as much info? If there is something I can read regarding this, I am more than happy to.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.