title: IllegalStateException: Session/EntityManager is closed
body: <p>I'm trying to implement his Java code with Hibernate in order to make SQL queries:</p>
  
  <pre><code>public List&lt;AttendeeModel&gt; getListOfCds(int firstRow, int rowCount) {
          List&lt;AttendeeModel&gt; cdList = null;
          try {
              session.beginTransaction();
              Criteria criteria = session.createCriteria(AttendeeModel.class);
              criteria.setFirstResult(firstRow);
              criteria.setMaxResults(rowCount);
              if (criteria != null) {
                  cdList = (List&lt;AttendeeModel&gt;) criteria.list();
              }
              session.getTransaction().commit();
          } catch (Exception e) {
              e.printStackTrace();
              session.getTransaction().rollback();
          }
          return cdList;
      }
  
      public int countRows() {
          try {
              session.beginTransaction();
              Criteria criteria = session.createCriteria(AttendeeModel.class);
              if (criteria != null) {
                  return criteria.list().size();
              }
              session.getTransaction().commit();
          } catch (Exception e) {
              e.printStackTrace();
              session.getTransaction().rollback();
          }
          return 0;
      }
  </code></pre>
  
  <p>But for some reason I get this error:</p>
  
  <pre><code> java.lang.IllegalStateException: Session/EntityManager is closed
  </code></pre>
  
  <p>Do you know how I can fix this issue?</p>