public void testSave() throws Exception {
    CompassSession session = compass.openSession();
    // (AGR_OSEM) ... CompassTransaction tr = session.beginTransaction();

    Session hibSession = sessionFactory.openSession();
    Transaction hibTr = hibSession.beginTransaction();

    Roof r1 = new Roof();
    r1.setName("the roof");

    Foundations f1 = new Foundations();
    f1.setName("foundations");

    House h1 = new House();
    h1.setName("my house");
    h1.setRoof(r1);
    r1.setHouse(h1);
    h1.setFoundations(f1);

    // (AGR_OSEM) ... assertEquals(0,
    // session.queryBuilder().matchAll().setTypes(Roof.class).hits().length());
    // (AGR_OSEM) ... assertEquals(0,
    // session.queryBuilder().matchAll().setTypes(House.class).hits().length());

    hibSession.save(h1);

    // objects are present in index after save, before commit

    // (AGR_OSEM) ... assertEquals(1,
    // session.queryBuilder().matchAll().setTypes(Roof.class).hits().length());
    // (AGR_OSEM) ... assertEquals(1,
    // session.queryBuilder().matchAll().setTypes(House.class).hits().length());

    // (AGR_OSEM) ... tr.commit();
    session.close();

    hibTr.commit();
    hibSession.close();
  }
  public void testErrorDuringUpdateOwneeDoesNotLeakMemory() throws Exception {
    Session hibSession = sessionFactory.openSession();
    Transaction hibTr = hibSession.beginTransaction();

    CompassSession session = compass.openSession();
    // (AGR_OSEM) ... CompassTransaction tr = session.beginTransaction();

    Roof r1 = new Roof();
    r1.setName("the roof");

    House h1 = new House();
    h1.setName("my house");
    h1.setRoof(r1);
    r1.setHouse(h1);

    hibSession.save(h1);

    // (AGR_OSEM) ... tr.commit();
    session.close();

    hibTr.commit();
    hibSession.close();

    hibSession = sessionFactory.openSession();
    hibTr = hibSession.beginTransaction();

    session = compass.openSession();
    // (AGR_OSEM) ... tr = session.beginTransaction();

    //        h1 = (House) hibSession.get(House.class, h1.getId());
    Roof r2 = new Roof();
    r2.setName("the new roof");
    h1.setRoof(r2);
    r2.setHouse(h1);
    r2.throwError = true;

    try {
      hibSession.update(h1);
      fail("should throw error");
    } catch (RuntimeException ex) {
      // good
      // (AGR_OSEM) ... tr.rollback();
      session.close();

      hibTr.rollback();
      hibSession.close();
    }

    Map pendingCreate = (Map) getProperty(hibernateEventListener, "pendingCreate");
    assertTrue(pendingCreate.isEmpty());
    Map pendingSave = (Map) getProperty(hibernateEventListener, "pendingSave");
    assertTrue(pendingSave.isEmpty());
  }