From 4543ab176b524e9fb45a0be1cd4fe11081c2b7ef Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 12 Oct 2021 13:22:33 +0200 Subject: [PATCH] Re-enabled additional tests --- .../IdentityJoinedSubclassBatchingTest.java | 137 +++++++++--------- .../JoinedSubclassBatchingTest.java | 109 +++++++------- .../SequenceJoinedSubclassBatchingTest.java | 127 ++++++++-------- 3 files changed, 183 insertions(+), 190 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java (67%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java (70%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java (67%) diff --git a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java similarity index 67% rename from hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java index c84dba6c64..91e1b70577 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/IdentityJoinedSubclassBatchingTest.java @@ -4,10 +4,25 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.joinedsubclassbatch; +package org.hibernate.orm.test.joinedsubclassbatch; import java.io.Serializable; import java.math.BigDecimal; + +import org.hibernate.ScrollMode; +import org.hibernate.ScrollableResults; +import org.hibernate.cfg.Environment; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; @@ -20,19 +35,8 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.ManyToOne; -import org.hibernate.ScrollMode; -import org.hibernate.ScrollableResults; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Assert; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; /** * Test batching of insert,update,delete on joined subclasses @@ -40,59 +44,57 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; * @author dcebotarenco */ @TestForIssue(jiraKey = "HHH-2558") -@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class) -public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsIdentityColumns.class) +@DomainModel( + annotatedClasses = { + IdentityJoinedSubclassBatchingTest.Person.class, + IdentityJoinedSubclassBatchingTest.Employee.class, + IdentityJoinedSubclassBatchingTest.Customer.class + } +) +@SessionFactory +@ServiceRegistry( + settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20") +) +public class IdentityJoinedSubclassBatchingTest { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - Employee.class, - Customer.class - }; - } - @Override - public void configure(Configuration cfg) { - cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" ); + @Test + public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 20, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { - doBatchInsertUpdateJoined( 20, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 19, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { - doBatchInsertUpdateJoined( 19, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 21, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { - doBatchInsertUpdateJoined( 21, 20 ); + public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize, scope ); } @Test - public void testBatchInsertUpdateSizeEqJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize ); + public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize - 1, scope ); } @Test - public void testBatchInsertUpdateSizeLtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize - 1 ); + public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize + 1, scope ); } - @Test - public void testBatchInsertUpdateSizeGtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize + 1 ); - } + public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) { - public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { - - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { for ( int i = 0; i < nEntities; i++ ) { Employee e = new Employee(); e.getId(); @@ -110,36 +112,34 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) + "select e from Employee e" ) .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); e.setTitle( "Unknown" ); } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) + "select e from Employee e" ) .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } ); } @Test - public void testAssertSubclassInsertedSuccessfullyAfterCommit() { + public void testAssertSubclassInsertedSuccessfullyAfterCommit(SessionFactoryScope scope) { final int nEntities = 10; - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { for ( int i = 0; i < nEntities; i++ ) { Employee e = new Employee(); e.setName( "Mark" ); @@ -152,19 +152,18 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa } } ); - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); - Assert.assertEquals( nEntities, numberOfInsertedEmployee ); + assertEquals( nEntities, numberOfInsertedEmployee ); } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) + "select e from Employee e" ) .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } ); @@ -172,9 +171,10 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa } @Test - public void testAssertSubclassInsertedSuccessfullyAfterFlush() { + public void testAssertSubclassInsertedSuccessfullyAfterFlush(SessionFactoryScope scope) { + + scope.inTransaction( s -> { - doInHibernate( this::sessionFactory, s -> { Employee e = new Employee(); e.setName( "Mark" ); e.setTitle( "internal sales" ); @@ -186,18 +186,17 @@ public class IdentityJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa s.flush(); long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); - Assert.assertEquals( 1L, numberOfInsertedEmployee ); + assertEquals( 1L, numberOfInsertedEmployee ); } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) + "select e from Employee e" ) .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java similarity index 70% rename from hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java index 46c0761e45..53df385a15 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java @@ -4,10 +4,24 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.joinedsubclassbatch; +package org.hibernate.orm.test.joinedsubclassbatch; import java.io.Serializable; import java.math.BigDecimal; + +import org.hibernate.ScrollMode; +import org.hibernate.ScrollableResults; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.cfg.Environment; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; @@ -19,76 +33,61 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.ManyToOne; -import org.hibernate.ScrollMode; -import org.hibernate.ScrollableResults; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; - /** * Test batching of insert,update,delete on joined subclasses * * @author dcebotarenco */ @TestForIssue(jiraKey = "HHH-2558") -public class JoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { +@DomainModel( + annotatedClasses = { + JoinedSubclassBatchingTest.Person.class, + JoinedSubclassBatchingTest.Employee.class, + JoinedSubclassBatchingTest.Customer.class + } +) +@SessionFactory +@ServiceRegistry( + settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20") +) +public class JoinedSubclassBatchingTest { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - Employee.class, - Customer.class - }; - } - - @Override - public void configure(Configuration cfg) { - cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" ); + @Test + public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 20, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { - doBatchInsertUpdateJoined( 20, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 19, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { - doBatchInsertUpdateJoined( 19, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 21, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { - doBatchInsertUpdateJoined( 21, 20 ); + public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize, scope ); } @Test - public void testBatchInsertUpdateSizeEqJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize ); + public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize - 1, scope ); } @Test - public void testBatchInsertUpdateSizeLtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize - 1 ); + public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize + 1, scope ); } - @Test - public void testBatchInsertUpdateSizeGtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize + 1 ); - } + public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) { - public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { - - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { for ( int i = 0; i < nEntities; i++ ) { Employee e = new Employee(); e.getId(); @@ -106,26 +105,24 @@ public class JoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) - .scroll( ScrollMode.FORWARD_ONLY ); + "select e from Employee e" ) + .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); e.setTitle( "Unknown" ); } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) - .scroll( ScrollMode.FORWARD_ONLY ); + "select e from Employee e" ) + .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java similarity index 67% rename from hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java index 46165aa0dd..688b156188 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/joinedsubclassbatch/SequenceJoinedSubclassBatchingTest.java @@ -4,10 +4,25 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.joinedsubclassbatch; +package org.hibernate.orm.test.joinedsubclassbatch; import java.io.Serializable; import java.math.BigDecimal; + +import org.hibernate.ScrollMode; +import org.hibernate.ScrollableResults; +import org.hibernate.cfg.Environment; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.Setting; +import org.junit.jupiter.api.Test; + import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Embedded; @@ -20,19 +35,7 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.ManyToOne; -import org.hibernate.ScrollMode; -import org.hibernate.ScrollableResults; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Assert; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test batching of insert,update,delete on joined subclasses using SEQUENCE @@ -40,59 +43,56 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; * @author Vlad Mihalcea */ @TestForIssue(jiraKey = "HHH-12968\n") -@RequiresDialectFeature(DialectChecks.SupportsSequences.class) -public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCase { +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class) +@DomainModel( + annotatedClasses = { + SequenceJoinedSubclassBatchingTest.Person.class, + SequenceJoinedSubclassBatchingTest.Employee.class, + SequenceJoinedSubclassBatchingTest.Customer.class + } +) +@SessionFactory +@ServiceRegistry( + settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "20") +) +public class SequenceJoinedSubclassBatchingTest { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Person.class, - Employee.class, - Customer.class - }; - } - - @Override - public void configure(Configuration cfg) { - cfg.setProperty( Environment.STATEMENT_BATCH_SIZE, "20" ); + @Test + public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 20, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrEqualWithBatch() { - doBatchInsertUpdateJoined( 20, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 19, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrLessThenBatch() { - doBatchInsertUpdateJoined( 19, 20 ); + public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch(SessionFactoryScope scope) { + doBatchInsertUpdateJoined( 21, 20, scope ); } @Test - public void doBatchInsertUpdateJoinedSubclassNrBiggerThenBatch() { - doBatchInsertUpdateJoined( 21, 20 ); + public void testBatchInsertUpdateSizeEqJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize, scope ); } @Test - public void testBatchInsertUpdateSizeEqJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize ); + public void testBatchInsertUpdateSizeLtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize - 1, scope ); } @Test - public void testBatchInsertUpdateSizeLtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize - 1 ); + public void testBatchInsertUpdateSizeGtJdbcBatchSize(SessionFactoryScope scope) { + int batchSize = scope.getSessionFactory().getSessionFactoryOptions().getJdbcBatchSize(); + doBatchInsertUpdateJoined( 50, batchSize + 1, scope ); } - @Test - public void testBatchInsertUpdateSizeGtJdbcBatchSize() { - int batchSize = sessionFactory().getSettings().getJdbcBatchSize(); - doBatchInsertUpdateJoined( 50, batchSize + 1 ); - } + public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush, SessionFactoryScope scope) { - public void doBatchInsertUpdateJoined(int nEntities, int nBeforeFlush) { - - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { for ( int i = 0; i < nEntities; i++ ) { Employee e = new Employee(); e.getId(); @@ -110,35 +110,33 @@ public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) - .scroll( ScrollMode.FORWARD_ONLY ); + "select e from Employee e" ) + .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); e.setTitle( "Unknown" ); } } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) - .scroll( ScrollMode.FORWARD_ONLY ); + "select e from Employee e" ) + .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } ); } @Test - public void testAssertSubclassInsertedSuccessfullyAfterFlush() { + public void testAssertSubclassInsertedSuccessfullyAfterFlush(SessionFactoryScope scope) { - doInHibernate( this::sessionFactory, s -> { + scope.inTransaction( s -> { Employee e = new Employee(); e.setName( "Mark" ); e.setTitle( "internal sales" ); @@ -150,18 +148,17 @@ public class SequenceJoinedSubclassBatchingTest extends BaseCoreFunctionalTestCa s.flush(); long numberOfInsertedEmployee = (long) s.createQuery( "select count(e) from Employee e" ).uniqueResult(); - Assert.assertEquals( 1L, numberOfInsertedEmployee ); + assertEquals( 1L, numberOfInsertedEmployee ); } ); - doInHibernate( this::sessionFactory, s -> { - int i = 0; + scope.inTransaction( s -> { ScrollableResults sr = s.createQuery( - "select e from Employee e" ) + "select e from Employee e" ) .scroll( ScrollMode.FORWARD_ONLY ); while ( sr.next() ) { - Employee e = (Employee) sr.get( ); + Employee e = (Employee) sr.get(); s.delete( e ); } } );