use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.
the class SessionWithSharedConnectionTest method testSharedTransactionContextFlushBeforeCompletion.
// @Test
// @TestForIssue( jiraKey = "HHH-7090" )
// public void testSharedTransactionContextAutoJoining() {
// Session session = sessionFactory().openSession();
// session.getTransaction().begin();
//
// Session secondSession = session.sessionWithOptions()
// .transactionContext()
// .autoJoinTransactions( true )
// .openSession();
//
// // directly assert state of the second session
// assertFalse( ((SessionImplementor) secondSession).shouldAutoJoinTransaction() );
//
// secondSession.close();
// session.close();
// }
@Test
@TestForIssue(jiraKey = "HHH-7090")
public void testSharedTransactionContextFlushBeforeCompletion() {
Session session = sessionFactory().openSession();
session.getTransaction().begin();
Session secondSession = session.sessionWithOptions().transactionContext().flushBeforeCompletion(true).autoClose(true).openSession();
// directly assert state of the second session
// assertTrue( ((SessionImplementor) secondSession).isFlushBeforeCompletionEnabled() );
// now try it out
Integer id = (Integer) secondSession.save(new IrrelevantEntity());
session.getTransaction().commit();
assertFalse(((SessionImplementor) session).isClosed());
assertTrue(((SessionImplementor) secondSession).isClosed());
session.close();
assertTrue(((SessionImplementor) session).isClosed());
assertTrue(((SessionImplementor) secondSession).isClosed());
session = sessionFactory().openSession();
session.getTransaction().begin();
IrrelevantEntity it = (IrrelevantEntity) session.byId(IrrelevantEntity.class).load(id);
assertNotNull(it);
session.delete(it);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.
the class SessionWithSharedConnectionTest method testChildSessionCallsAfterTransactionAction.
@Test
@TestForIssue(jiraKey = "HHH-7239")
public void testChildSessionCallsAfterTransactionAction() throws Exception {
Session session = openSession();
final String postCommitMessage = "post commit was called";
EventListenerRegistry eventListenerRegistry = sessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
//register a post commit listener
eventListenerRegistry.appendListeners(EventType.POST_COMMIT_INSERT, new PostInsertEventListener() {
@Override
public void onPostInsert(PostInsertEvent event) {
((IrrelevantEntity) event.getEntity()).setName(postCommitMessage);
}
@Override
public boolean requiresPostCommitHanding(EntityPersister persister) {
return true;
}
});
session.getTransaction().begin();
IrrelevantEntity irrelevantEntityMainSession = new IrrelevantEntity();
irrelevantEntityMainSession.setName("main session");
session.save(irrelevantEntityMainSession);
//open secondary session to also insert an entity
Session secondSession = session.sessionWithOptions().connection().flushBeforeCompletion(true).autoClose(true).openSession();
IrrelevantEntity irrelevantEntitySecondarySession = new IrrelevantEntity();
irrelevantEntitySecondarySession.setName("secondary session");
secondSession.save(irrelevantEntitySecondarySession);
session.getTransaction().commit();
//both entities should have their names updated to the postCommitMessage value
assertEquals(postCommitMessage, irrelevantEntityMainSession.getName());
assertEquals(postCommitMessage, irrelevantEntitySecondarySession.getName());
}
use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.
the class LegacyPostCommitListenerTest 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, ((LegacyPostCommitUpdateEventListener) postCommitUpdateEventListener).fired);
}
use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.
the class PostCommitListenerTest 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();
Assert.assertEquals(0, ((TestPostCommitUpdateEventListener) postCommitUpdateEventListener).sucess);
Assert.assertEquals(1, ((TestPostCommitUpdateEventListener) postCommitUpdateEventListener).failed);
}
use of org.hibernate.IrrelevantEntity in project hibernate-orm by hibernate.
the class PostCommitListenerTest 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();
Assert.assertEquals(0, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).success);
Assert.assertEquals(1, ((TestPostCommitDeleteEventListener) postCommitDeleteEventListener).failed);
}
Aggregations