String query = "select o from " + entityClass.getName() + " o fetch all properties";
if (WikiNode.class.isAssignableFrom(entityClass)) {
// If it's a WikiNode, fetch the associated User instances, avoiding N+1 selects
query = "select o from " + entityClass.getName() + " o inner join fetch o.createdBy left join fetch o.lastModifiedBy fetch all properties";
}
ScrollableResults cursor = ftSession.createQuery(query).scroll();
cursor.last();
int count = cursor.getRowNumber() + 1;
log.debug("total documents in database: " + count);