use of org.hibernate.testing.TestForIssue in project hibernate-orm by hibernate.
the class SessionWithSharedConnectionTest method testSharedTransactionContextSessionClosing.
@Test
@TestForIssue(jiraKey = "HHH-7090")
public void testSharedTransactionContextSessionClosing() {
Session session = sessionFactory().openSession();
session.getTransaction().begin();
Session secondSession = session.sessionWithOptions().transactionContext().openSession();
secondSession.createCriteria(IrrelevantEntity.class).list();
//the list should have registered and then released a JDBC resource
assertFalse(((SessionImplementor) secondSession).getJdbcCoordinator().getResourceRegistry().hasRegisteredResources());
assertTrue(session.isOpen());
assertTrue(secondSession.isOpen());
assertSame(session.getTransaction(), secondSession.getTransaction());
session.getTransaction().commit();
assertTrue(session.isOpen());
assertTrue(secondSession.isOpen());
secondSession.close();
assertTrue(session.isOpen());
assertFalse(secondSession.isOpen());
session.close();
assertFalse(session.isOpen());
assertFalse(secondSession.isOpen());
}
use of org.hibernate.testing.TestForIssue 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.testing.TestForIssue in project hibernate-orm by hibernate.
the class SessionWithSharedConnectionTest method testChildSessionTwoTransactions.
@Test
@TestForIssue(jiraKey = "HHH-7239")
public void testChildSessionTwoTransactions() throws Exception {
Session session = openSession();
session.getTransaction().begin();
//open secondary session with managed options
Session secondarySession = session.sessionWithOptions().connection().flushBeforeCompletion(true).autoClose(true).openSession();
//the secondary session should be automatically closed afterQuery the commit
session.getTransaction().commit();
assertFalse(secondarySession.isOpen());
//should be able to create a new transaction and carry on using the original session
session.getTransaction().begin();
session.getTransaction().commit();
}
use of org.hibernate.testing.TestForIssue 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.testing.TestForIssue in project hibernate-orm by hibernate.
the class QueryTest method testMemberOfSyntax.
@Test
@TestForIssue(jiraKey = "HHH-5209")
public void testMemberOfSyntax() {
// performs syntax checking of the MEMBER OF predicate against a basic collection
Session s = openSession();
s.createQuery("from EntityWithAnElementCollection e where 'abc' member of e.someStrings").list();
s.close();
}
Aggregations