/** Test that session-closed protections work properly in all environments. */
  @Test
  public void testSessionClosedProtections() throws Throwable {
    prepare();
    Session s = getSessionUnderTest();
    release(s);
    done();
    assertFalse(s.isOpen());
    assertFalse(s.isConnected());
    assertNotNull(s.getStatistics());
    assertNotNull(s.toString());

    try {
      s.createQuery("from Silly").list();
      fail("allowed to create query on closed session");
    } catch (Throwable ignore) {
    }

    try {
      s.getTransaction();
      fail("allowed to access transaction on closed session");
    } catch (Throwable ignore) {
    }

    try {
      s.close();
      fail("allowed to close already closed session");
    } catch (Throwable ignore) {
    }

    try {
      s.isDirty();
      fail("allowed to check dirtiness of closed session");
    } catch (Throwable ignore) {
    }
  }
Beispiel #2
0
  /**
   * Will clear-off the content in the current Hibernate Session
   *
   * @see org.hibernate.Session
   */
  @Transactional(readOnly = false)
  public void clearSession() {

    Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();

    if (log.isDebugEnabled()) {
      log.debug("Entity Count  before clear() : " + session.getStatistics().getEntityCount());
      log.debug(
          "Collection Count before clear() : " + session.getStatistics().getCollectionCount());
    }

    session.clear();

    if (log.isDebugEnabled()) {
      log.debug("Entity Count  after clear() : " + session.getStatistics().getEntityCount());
      log.debug("Collection Count after clear() : " + session.getStatistics().getCollectionCount());
    }
  }
Beispiel #3
0
 public SessionStatistics getStatistics() {
   return session.getStatistics();
 }