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.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@ -414,64 +415,53 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
comment = "skip dialects that throw PessimisticLockException"
)
public void testBulkOperationsInTwoConcurrentSessions() throws Exception {
Session s = openSession();
s.getTransaction().begin();
doInHibernate( this::sessionFactory, s -> {
Location mars = new Location( "Mars" );
s.persist( mars );
Location mars = new Location( "Mars" );
s.persist( mars );
Location earth = new Location( "Earth" );
s.persist( earth );
Location earth = new Location( "Earth" );
s.persist( earth );
Hive hive = new Hive();
hive.setLocation( mars );
s.persist( hive );
Hive hive = new Hive();
hive.setLocation( mars );
s.persist( hive );
Alien alien = new Alien();
alien.setIdentity( "Uncle Martin" );
alien.setSpecies( "Martian" );
alien.setHive( hive );
hive.getMembers().add( alien );
mars.addBeing( alien );
Alien alien = new Alien();
alien.setIdentity( "Uncle Martin" );
alien.setSpecies( "Martian" );
alien.setHive( hive );
hive.getMembers().add( alien );
mars.addBeing( alien );
s.persist( alien );
s.persist( alien );
Human human = new Human();
human.setIdentity( "Jane Doe" );
human.setSex( 'M' );
earth.addBeing( human );
Human human = new Human();
human.setIdentity( "Jane Doe" );
earth.addBeing( human );
s.persist( 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();
s.close();
doInHibernate( this::sessionFactory, s2 -> {
assertEquals( 1, s2.createQuery( "delete from Being where species = 'Martian'" ).executeUpdate() );
} );
} );
Session s1 = openSession();
s1.beginTransaction();
assertEquals(
1,
s1.createQuery( "update Being set identity = 'John Doe' where identity = 'Jane Doe'" )
.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();
doInHibernate( this::sessionFactory, s -> {
Human 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();
} );
}
}