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.
|