Search in sources :

Example 11 with IrrelevantEntity

use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.

the class LegacyPostCommitListenerTest method testPostCommitDeleteListenerRollback.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitDeleteListenerRollback() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("Irrelevant");
    session.save(irrelevantEntity);
    session.flush();
    transaction.commit();
    session.close();
    session = openSession();
    transaction = session.beginTransaction();
    session.delete(irrelevantEntity);
    session.flush();
    transaction.rollback();
    session.close();
    //the legacy implementation fires the listener on failure as well
    Assert.assertEquals(1, ((LegacyPostCommitDeleteEventListener) postCommitDeleteEventListener).fired);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 12 with IrrelevantEntity

use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.

the class LegacyPostCommitListenerTest method testPostCommitInsertListenerSuccess.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitInsertListenerSuccess() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("Irrelevant");
    session.save(irrelevantEntity);
    session.flush();
    transaction.commit();
    session.close();
    Assert.assertEquals(1, ((LegacyPostCommitInsertEventListener) postCommitInsertEventListener).fired);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with IrrelevantEntity

use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.

the class LegacyPostCommitListenerTest method testPostCommitUpdateListenerRollback.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitUpdateListenerRollback() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("Irrelevant");
    session.save(irrelevantEntity);
    session.flush();
    transaction.commit();
    session.close();
    session = openSession();
    transaction = session.beginTransaction();
    irrelevantEntity.setName("Irrelevant 2");
    session.update(irrelevantEntity);
    session.flush();
    transaction.rollback();
    session.close();
    //the legacy implementation fires the listener on failure as well
    Assert.assertEquals(1, ((LegacyPostCommitUpdateEventListener) postCommitUpdateEventListener).fired);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with IrrelevantEntity

use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.

the class PostCommitListenerTest method testPostCommitUpdateListenerSuccess.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitUpdateListenerSuccess() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("Irrelevant");
    session.save(irrelevantEntity);
    session.flush();
    transaction.commit();
    session = openSession();
    transaction = session.beginTransaction();
    irrelevantEntity.setName("Irrelevant 2");
    session.update(irrelevantEntity);
    session.flush();
    transaction.commit();
    session.close();
    Assert.assertEquals(1, ((TestPostCommitUpdateEventListener) postCommitUpdateEventListener).sucess);
    Assert.assertEquals(0, ((TestPostCommitUpdateEventListener) postCommitUpdateEventListener).failed);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

IrrelevantEntity (org.hibernate.IrrelevantEntity)14 Session (org.hibernate.Session)14 TestForIssue (org.hibernate.testing.TestForIssue)14 Test (org.junit.Test)14 Transaction (org.hibernate.Transaction)12 EventListenerRegistry (org.hibernate.event.service.spi.EventListenerRegistry)1 PostInsertEvent (org.hibernate.event.spi.PostInsertEvent)1 PostInsertEventListener (org.hibernate.event.spi.PostInsertEventListener)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1