title: Hibernate session within inner class
body: <p>I have an issue with getting session on anonymus inner class in hibernate with spring session factory.
  Here is the code:</p>
  
  <pre><code>public class DomainDaoImpl extends BasicDaoImpl&lt;Domain&gt; implements Iterable&lt;Collection&lt;Domain&gt;&gt; {
  
  ...
  
  @Override
  public Iterator&lt;Collection&lt;Domain&gt;&gt; iterator() {
      return (new Iterator&lt;Collection&lt;Domain&gt;&gt;() {
          private int counter = 0;
          public static final int LIMIT = 100;
  
          ...
  
          @Override
          @Transactional(readOnly = true)
          public Collection&lt;Domain&gt; next() {
              final Criteria criteria = getCurrentSession().createCriteria(Domain.class);
              final LinkedHashSet&lt;Domain&gt; result = new LinkedHashSet&lt;Domain&gt;();
  
              List resultList = null;
              while (!(resultList = criteria.list()).isEmpty()) {
                  criteria.setFirstResult((counter++ * LIMIT) + 1);
                  criteria.setMaxResults(LIMIT);
                  result.addAll(resultList);
              }
              return result;
          }
  
          ...
      });
  </code></pre>
  
  <p>The issue is <em>org.hibernate.HibernateException: No Session found for current thread</em>
  this happens usually when DAO method is not within transaction.
  So how to make it work with an inner class?</p>