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
1 changed files with 39 additions and 49 deletions

View File

@ -22,6 +22,7 @@ import org.hibernate.testing.SkipForDialect;
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,64 +415,53 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
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" );
s.persist( mars );
Location mars = new Location( "Mars" ); Location earth = new Location( "Earth" );
s.persist( mars ); s.persist( earth );
Location earth = new Location( "Earth" ); Hive hive = new Hive();
s.persist( earth ); hive.setLocation( mars );
s.persist( hive );
Hive hive = new Hive(); Alien alien = new Alien();
hive.setLocation( mars ); alien.setIdentity( "Uncle Martin" );
s.persist( hive ); alien.setSpecies( "Martian" );
alien.setHive( hive );
hive.getMembers().add( alien );
mars.addBeing( alien );
Alien alien = new Alien(); s.persist( alien );
alien.setIdentity( "Uncle Martin" );
alien.setSpecies( "Martian" );
alien.setHive( hive );
hive.getMembers().add( alien );
mars.addBeing( alien );
s.persist( alien ); Human human = new Human();
human.setIdentity( "Jane Doe" );
human.setSex( 'M' );
earth.addBeing( human );
Human human = new Human(); s.persist( human );
human.setIdentity( "Jane Doe" ); } );
earth.addBeing( human );
s.persist( human ); doInHibernate( this::sessionFactory, s1 -> {
assertEquals(
1,
s1.createQuery( "update Being set identity = 'John Doe' where identity = 'Jane Doe'" )
.executeUpdate()
);
s.getTransaction().commit(); doInHibernate( this::sessionFactory, s2 -> {
s.close(); assertEquals( 1, s2.createQuery( "delete from Being where species = 'Martian'" ).executeUpdate() );
} );
} );
Session s1 = openSession(); doInHibernate( this::sessionFactory, s -> {
s1.beginTransaction(); Human human = (Human) s.createQuery( "from Being" ).uniqueResult();
assertEquals( assertEquals( "John Doe", human.getIdentity() );
1, s.createQuery( "delete from Being" ).executeUpdate();
s1.createQuery( "update Being set identity = 'John Doe' where identity = 'Jane Doe'" ) s.createQuery( "delete from Hive" ).executeUpdate();
.executeUpdate() s.createQuery( "delete from Location" ).executeUpdate();
); } );
Session s2 = openSession();
s2.beginTransaction();
assertEquals( 1, s2.createQuery( "delete from Being where species = 'Martian'" ).executeUpdate() );
s2.getTransaction().commit();
s1.getTransaction().commit();
s1.close();
s2.close();
s = openSession();
s.getTransaction().begin();
human = (Human) s.createQuery( "from Being" ).uniqueResult();
assertEquals( "John Doe", human.getIdentity() );
s.createQuery( "delete from Being" ).executeUpdate();
s.createQuery( "delete from Hive" ).executeUpdate();
s.createQuery( "delete from Location" ).executeUpdate();
s.getTransaction().commit();
s.close();
} }
} }