Search in sources :

Example 21 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class StoreDeletedData method testMaximizeInDisjunction.

@Test
@TestForIssue(jiraKey = "HHH-7800")
public void testMaximizeInDisjunction() {
    List<Integer> queryIds = Arrays.asList(id2, id3);
    AuditDisjunction disjunction = AuditEntity.disjunction();
    for (Integer id : queryIds) {
        AuditCriterion crit = AuditEntity.revisionNumber().maximize().add(AuditEntity.id().eq(id)).add(AuditEntity.revisionType().ne(RevisionType.DEL));
        disjunction.add(crit);
    // Workaround: using this line instead works correctly:
    // disjunction.add(AuditEntity.conjunction().add(crit));
    }
    List<?> beforeDeletionRevisions = getAuditReader().createQuery().forRevisionsOfEntity(StrIntTestEntity.class, false, false).add(disjunction).addOrder(AuditEntity.property("id").asc()).getResultList();
    Assert.assertEquals(2, beforeDeletionRevisions.size());
    Object[] result1 = (Object[]) beforeDeletionRevisions.get(0);
    Object[] result2 = (Object[]) beforeDeletionRevisions.get(1);
    Assert.assertEquals(new StrIntTestEntity("b", 20, id2), result1[0]);
    // Making sure that we have received an entity added at revision 3.
    Assert.assertEquals(3, ((SequenceIdRevisionEntity) result1[1]).getId());
    Assert.assertEquals(RevisionType.ADD, result1[2]);
    Assert.assertEquals(new StrIntTestEntity("c", 30, id3), result2[0]);
    // Making sure that we have received an entity added at revision 3.
    Assert.assertEquals(3, ((SequenceIdRevisionEntity) result2[1]).getId());
    Assert.assertEquals(RevisionType.ADD, result2[2]);
}
Also used : StrIntTestEntity(org.hibernate.envers.test.entities.StrIntTestEntity) AuditDisjunction(org.hibernate.envers.query.criteria.AuditDisjunction) AuditCriterion(org.hibernate.envers.query.criteria.AuditCriterion) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 22 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class ProxyIdentifier method testNullReferenceWithNotFoundActionIgnoreInParent.

@Test
@TestForIssue(jiraKey = "HHH-8912")
public void testNullReferenceWithNotFoundActionIgnoreInParent() {
    ExtManyToOneNotAuditedNullEntity emtoRev2 = getAuditReader().find(ExtManyToOneNotAuditedNullEntity.class, emtonane1.getId(), 2);
    Assert.assertEquals(emtonane1, emtoRev2);
    Assert.assertNull(emtoRev2.getReference());
}
Also used : ExtManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ExtManyToOneNotAuditedNullEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 23 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class ProxyIdentifier method testNullReferenceWithNotFoundActionIgnore.

@Test
@TestForIssue(jiraKey = "HHH-8174")
public void testNullReferenceWithNotFoundActionIgnore() {
    ManyToOneNotAuditedNullEntity mtoRev2 = getAuditReader().find(ManyToOneNotAuditedNullEntity.class, mtonane1.getId(), 2);
    Assert.assertEquals(mtonane1, mtoRev2);
    Assert.assertNull(mtoRev2.getReference());
    ManyToManyNotAuditedNullEntity mtmRev2 = getAuditReader().find(ManyToManyNotAuditedNullEntity.class, mtmnane1.getId(), 2);
    Assert.assertEquals(mtmnane1, mtmRev2);
    Assert.assertTrue(mtmRev2.getReferences().isEmpty());
    OneToManyNotAuditedNullEntity otmRev2 = getAuditReader().find(OneToManyNotAuditedNullEntity.class, otmnane1.getId(), 2);
    Assert.assertEquals(otmnane1, otmRev2);
    Assert.assertTrue(otmRev2.getReferences().isEmpty());
}
Also used : OneToManyNotAuditedNullEntity(org.hibernate.envers.test.entities.onetomany.OneToManyNotAuditedNullEntity) ManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ManyToOneNotAuditedNullEntity) ExtManyToOneNotAuditedNullEntity(org.hibernate.envers.test.entities.manytoone.unidirectional.ExtManyToOneNotAuditedNullEntity) ManyToManyNotAuditedNullEntity(org.hibernate.envers.test.entities.manytomany.unidirectional.ManyToManyNotAuditedNullEntity) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 24 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class EvictAuditDataAfterCommitTest method testSessionCacheCollectionClear.

@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");
    Session session = openSession();
    session.getTransaction().begin();
    session.persist(ed1);
    session.persist(ed2);
    session.persist(ing1);
    session.persist(ing2);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed1 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed1.getId());
    ing1.setReference(ed1);
    ing2.setReference(ed1);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    Set<SetRefIngEntity> reffering = new HashSet<SetRefIngEntity>();
    reffering.add(ing1);
    reffering.add(ing2);
    ed2.setReffering(reffering);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().remove(ing1);
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.getTransaction().begin();
    ed2 = (SetRefEdEntity) session.load(SetRefEdEntity.class, ed2.getId());
    ed2.getReffering().iterator().next().setData("mod_data_ing_2");
    session.getTransaction().commit();
    checkEmptyAuditSessionCache(session, auditEntityNames);
    session.close();
}
Also used : SetRefIngEntity(org.hibernate.envers.test.entities.onetomany.SetRefIngEntity) SetRefEdEntity(org.hibernate.envers.test.entities.onetomany.SetRefEdEntity) Session(org.hibernate.Session) HashSet(java.util.HashSet) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 25 with TestForIssue

use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.

the class BasicIntegratorTest method testNoAudited.

/**
	 * Tests that nothing crazy happens if the hibernate-envers jar happens
	 * to be on the classpath but we have no audited entities
	 */
@Test
@TestForIssue(jiraKey = "HHH-9675")
public void testNoAudited() {
    new Configuration().buildSessionFactory().close();
    new Configuration().addAnnotatedClass(SimpleNonAuditedEntity.class).buildSessionFactory().close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

TestForIssue (org.hibernate.testing.TestForIssue)649 Test (org.junit.Test)647 Session (org.hibernate.Session)357 EntityManager (javax.persistence.EntityManager)97 List (java.util.List)91 Transaction (org.hibernate.Transaction)88 MetadataSources (org.hibernate.boot.MetadataSources)47 ArrayList (java.util.ArrayList)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)38 Query (org.hibernate.Query)28 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 Metadata (org.hibernate.boot.Metadata)24 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)24 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Map (java.util.Map)22 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)19 HashMap (java.util.HashMap)18 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)18 PersistentClass (org.hibernate.mapping.PersistentClass)18 HibernateException (org.hibernate.HibernateException)16