HHH-11740 - Default MultiTableBulkIdStrategy for DB2 does not work with connection pools

- Fix tests on PostgreSQL
This commit is contained in:
Vlad Mihalcea 2017-05-15 17:55:22 +03:00
parent 6a0a6d7562
commit 386b04872f

View File

@ -22,6 +22,7 @@
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -414,9 +415,7 @@ public void testNestedUnionedSubclasses() throws Exception {
comment = "skip dialects that throw PessimisticLockException" comment = "skip dialects that throw PessimisticLockException"
) )
public void testBulkOperationsInTwoConcurrentSessions() throws Exception { public void testBulkOperationsInTwoConcurrentSessions() throws Exception {
Session s = openSession(); doInHibernate( this::sessionFactory, s -> {
s.getTransaction().begin();
Location mars = new Location( "Mars" ); Location mars = new Location( "Mars" );
s.persist( mars ); s.persist( mars );
@ -438,40 +437,31 @@ public void testBulkOperationsInTwoConcurrentSessions() throws Exception {
Human human = new Human(); Human human = new Human();
human.setIdentity( "Jane Doe" ); human.setIdentity( "Jane Doe" );
human.setSex( 'M' );
earth.addBeing( human ); earth.addBeing( human );
s.persist( human ); s.persist( human );
} );
s.getTransaction().commit(); doInHibernate( this::sessionFactory, s1 -> {
s.close();
Session s1 = openSession();
s1.beginTransaction();
assertEquals( assertEquals(
1, 1,
s1.createQuery( "update Being set identity = 'John Doe' where identity = 'Jane Doe'" ) s1.createQuery( "update Being set identity = 'John Doe' where identity = 'Jane Doe'" )
.executeUpdate() .executeUpdate()
); );
Session s2 = openSession(); doInHibernate( this::sessionFactory, s2 -> {
s2.beginTransaction();
assertEquals( 1, s2.createQuery( "delete from Being where species = 'Martian'" ).executeUpdate() ); assertEquals( 1, s2.createQuery( "delete from Being where species = 'Martian'" ).executeUpdate() );
} );
} );
s2.getTransaction().commit(); doInHibernate( this::sessionFactory, s -> {
s1.getTransaction().commit(); Human human = (Human) s.createQuery( "from Being" ).uniqueResult();
s1.close();
s2.close();
s = openSession();
s.getTransaction().begin();
human = (Human) s.createQuery( "from Being" ).uniqueResult();
assertEquals( "John Doe", human.getIdentity() ); assertEquals( "John Doe", human.getIdentity() );
s.createQuery( "delete from Being" ).executeUpdate(); s.createQuery( "delete from Being" ).executeUpdate();
s.createQuery( "delete from Hive" ).executeUpdate(); s.createQuery( "delete from Hive" ).executeUpdate();
s.createQuery( "delete from Location" ).executeUpdate(); s.createQuery( "delete from Location" ).executeUpdate();
s.getTransaction().commit(); } );
s.close();
} }
} }