Search in sources :

Example 6 with IrrelevantEntity

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

the class PostCommitListenerTest 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, ((TestPostCommitInsertEventListener) postCommitInsertEventListener).success);
    Assert.assertEquals(0, ((TestPostCommitInsertEventListener) postCommitInsertEventListener).failed);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 7 with IrrelevantEntity

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

the class PostCommitListenerTest method testPostCommitInsertListenerRollback.

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

Example 8 with IrrelevantEntity

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

the class PostCommitListenerTest method testPostCommitDeleteListenerSuccess.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitDeleteListenerSuccess() {
    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.commit();
    session.close();
    Assert.assertEquals(1, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).success);
    Assert.assertEquals(0, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).failed);
}
Also used : Transaction(org.hibernate.Transaction) IrrelevantEntity(org.hibernate.IrrelevantEntity) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 9 with IrrelevantEntity

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

the class LegacyPostCommitListenerTest method testPostCommitDeleteListenerSuccess.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitDeleteListenerSuccess() {
    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.commit();
    session.close();
    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 10 with IrrelevantEntity

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

the class LegacyPostCommitListenerTest method testPostCommitInsertListenerRollback.

@Test
@TestForIssue(jiraKey = "HHH-1582")
public void testPostCommitInsertListenerRollback() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    IrrelevantEntity irrelevantEntity = new IrrelevantEntity();
    irrelevantEntity.setName("Irrelevant");
    session.save(irrelevantEntity);
    session.flush();
    transaction.rollback();
    session.close();
    //the legacy implementation fires the listener on failure as well 
    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)

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