@Test
  @Priority(10)
  public void initData() {
    EntityManager em = getEntityManager();

    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");

    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1");

    // Revision 1
    em.getTransaction().begin();

    em.persist(ed1);

    em.getTransaction().commit();

    // Revision 2

    em.getTransaction().begin();

    ed1 = em.find(SetRefEdEntity.class, ed1.getId());

    em.persist(ing1);

    ed1.setReffering(new HashSet<SetRefIngEntity>());
    ed1.getReffering().add(ing1);

    em.getTransaction().commit();

    //

    ed1_id = ed1.getId();

    ing1_id = ing1.getId();
  }
Beispiel #2
0
  @Test
  public void testCacheReferenceAccessAfterCollectionAccessRev2() {
    SetRefEdEntity ed2_rev2 = getAuditReader().find(SetRefEdEntity.class, ed2_id, 2);

    assert ed2_rev2.getReffering().size() == 2;
    for (SetRefIngEntity setRefIngEntity : ed2_rev2.getReffering()) {
      assert setRefIngEntity.getReference() == ed2_rev2;
    }
  }
Beispiel #3
0
  @Test
  public void testCacheReferenceAccessAfterCollectionAccessRev1() {
    SetRefEdEntity ed1_rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1);

    // It should be exactly the same object
    assert ed1_rev1.getReffering().size() == 2;
    for (SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering()) {
      assert setRefIngEntity.getReference() == ed1_rev1;
    }
  }
Beispiel #4
0
  @Test
  public void testCacheFindAfterCollectionAccessRev1() {
    SetRefEdEntity ed1_rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1);

    // Reading the collection
    assert ed1_rev1.getReffering().size() == 2;

    SetRefIngEntity ing1_rev1 = getAuditReader().find(SetRefIngEntity.class, ing1_id, 1);
    SetRefIngEntity ing2_rev1 = getAuditReader().find(SetRefIngEntity.class, ing2_id, 1);

    for (SetRefIngEntity setRefIngEntity : ed1_rev1.getReffering()) {
      assert setRefIngEntity == ing1_rev1 || setRefIngEntity == ing2_rev1;
    }
  }
Beispiel #5
0
  @Test
  @Priority(10)
  public void initData() {
    EntityManager em = getEntityManager();

    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2");

    SetRefIngEntity ing1 = new SetRefIngEntity(1, "data_ing_1");
    SetRefIngEntity ing2 = new SetRefIngEntity(2, "data_ing_2");

    // Revision 1
    em.getTransaction().begin();

    em.persist(ed1);
    em.persist(ed2);

    ing1.setReference(ed1);
    ing2.setReference(ed1);

    em.persist(ing1);
    em.persist(ing2);

    em.getTransaction().commit();

    // Revision 2
    em.getTransaction().begin();

    ing1 = em.find(SetRefIngEntity.class, ing1.getId());
    ing2 = em.find(SetRefIngEntity.class, ing2.getId());
    ed2 = em.find(SetRefEdEntity.class, ed2.getId());

    ing1.setReference(ed2);
    ing2.setReference(ed2);

    em.getTransaction().commit();

    //

    ed1_id = ed1.getId();
    ed2_id = ed2.getId();

    ing1_id = ing1.getId();
    ing2_id = ing2.getId();
  }
  @Test
  @TestForIssue(jiraKey = "HHH-6614")
  public void testSessionCacheCollectionClear() {
    final String[] auditEntityNames =
        new String[] {
          "org.hibernate.envers.test.entities.onetomany.SetRefEdEntity_AUD",
          "org.hibernate.envers.test.entities.onetomany.SetRefIngEntity_AUD"
        };

    SetRefEdEntity ed1 = new SetRefEdEntity(1, "data_ed_1");
    SetRefEdEntity ed2 = new SetRefEdEntity(2, "data_ed_2");
    SetRefIngEntity ing1 = new SetRefIngEntity(3, "data_ing_1");
    SetRefIngEntity ing2 = new SetRefIngEntity(4, "data_ing_2");

    getSession().getTransaction().begin();
    getSession().persist(ed1);
    getSession().persist(ed2);
    getSession().persist(ing1);
    getSession().persist(ing2);
    getSession().getTransaction().commit();
    checkEmptyAuditSessionCache(getSession(), auditEntityNames);

    getSession().getTransaction().begin();
    ed1 = (SetRefEdEntity) getSession().load(SetRefEdEntity.class, ed1.getId());
    ing1.setReference(ed1);
    ing2.setReference(ed1);
    getSession().getTransaction().commit();
    checkEmptyAuditSessionCache(getSession(), auditEntityNames);

    getSession().getTransaction().begin();
    ed2 = (SetRefEdEntity) getSession().load(SetRefEdEntity.class, ed2.getId());
    Set<SetRefIngEntity> reffering = new HashSet<SetRefIngEntity>();
    reffering.add(ing1);
    reffering.add(ing2);
    ed2.setReffering(reffering);
    getSession().getTransaction().commit();
    checkEmptyAuditSessionCache(getSession(), auditEntityNames);

    getSession().getTransaction().begin();
    ed2 = (SetRefEdEntity) getSession().load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().remove(ing1);
    getSession().getTransaction().commit();
    checkEmptyAuditSessionCache(getSession(), auditEntityNames);

    getSession().getTransaction().begin();
    ed2 = (SetRefEdEntity) getSession().load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().iterator().next().setData("mod_data_ing_2");
    getSession().getTransaction().commit();
    checkEmptyAuditSessionCache(getSession(), auditEntityNames);
  }
  @Test
  public void testHistoryOfEdId1() {
    SetRefEdEntity rev1 = getAuditReader().find(SetRefEdEntity.class, ed1_id, 1);

    assert rev1.getReffering().equals(Collections.EMPTY_SET);
  }