From d767d46d05a9a1f754dca6be870bbf9f17bdb553 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 3 Feb 2021 10:55:07 +0100 Subject: [PATCH] Fix most tests to work on all DBs and fix a bunch of connection leaks --- .github/workflows/contributor-build.yml | 8 +- ci/build-github.sh | 2 +- ci/build-travis.sh | 2 +- ci/build.sh | 10 +- docker_db.sh | 50 ++++++++- .../userguide/events/ListenerTest.java | 2 +- .../org/hibernate/userguide/hql/HQLTest.java | 7 ++ .../mapping/basic/NClobCharArrayTest.java | 6 +- .../mapping/basic/NClobStringTest.java | 6 +- .../userguide/mapping/basic/NClobTest.java | 6 +- .../mapping/basic/NationalizedTest.java | 6 +- .../mapping/basic/SubselectTest.java | 3 + .../mapping/basic/TypeCategoryTest.java | 6 +- gradle/databases.gradle | 43 ++++++- gradle/java-module.gradle | 13 ++- ...reparedStatementSpyConnectionProvider.java | 2 +- .../src/test/resources/hibernate.properties | 1 + .../org/hibernate/dialect/DB2Dialect.java | 2 +- .../org/hibernate/dialect/DerbyDialect.java | 5 + .../hibernate/dialect/MariaDB103Dialect.java | 17 +++ .../AbstractMultiTableBulkIdStrategyImpl.java | 2 +- .../hibernate/jpa/test/cascade/MergeTest.java | 6 +- .../jpa/test/criteria/TreatKeywordTest.java | 8 +- .../test/criteria/basic/PredicateTest.java | 2 + .../CriteriaLiteralWithSingleQuoteTest.java | 3 +- .../selectcase/GroupBySelectCaseTest.java | 2 + .../SelectCaseLiteralHandlingBindTest.java | 5 + .../criteria/selectcase/SelectCaseTest.java | 2 + .../jpa/test/metamodel/Translation.java | 2 + .../hibernate/jpa/test/query/QueryTest.java | 11 ++ .../schemagen/JpaSchemaGeneratorTest.java | 8 +- .../transaction/FlushAndTransactionTest.java | 5 + .../batch/JtaWithFailingBatchTest.java | 7 +- .../criteria/BasicCriteriaExecutionTests.java | 5 + .../SearchedCaseExpressionTest.java | 4 + .../query/hhh14156/HHH14156Test.java | 6 + .../hibernate/secure/JaccIntegratorTest.java | 2 +- ...dableWithOneToMany_HHH_11302_xml_Test.java | 1 + .../test/annotations/lob/hhh4635/LobTest.java | 3 + .../annotations/query/QueryAndSQLTest.java | 3 + ...obalTemporaryTableBulkCompositeIdTest.java | 9 +- .../org/hibernate/test/cascade/MergeTest.java | 6 +- .../test/cdi/converters/legacy/QueryTest.java | 14 +-- .../BeforeCompletionReleaseTest.java | 1 + .../ConnectionsReleaseAutoCommitTest.java | 4 + .../test/converter/AndNationalizedTests.java | 12 +- .../org/hibernate/test/criteria/InTest.java | 4 + .../criterion/NationalizedIgnoreCaseTest.java | 2 + .../SQLServerDialectCollationTest.java | 34 ++++-- ...QLServerDialectTempTableCollationTest.java | 105 ++++++++++++------ .../fileimport/MultiLineImportFileTest.java | 15 ++- .../test/hql/ASTParserLoadingTest.java | 3 + .../org/hibernate/test/hql/CoalesceTest.java | 2 + .../hibernate/test/hql/WithClauseTest.java | 3 + .../test/hql/size/ManyToManySizeTest.java | 8 ++ .../test/hql/size/OneToManySizeTest.java | 7 ++ .../HiLoSequenceMismatchStrategyTest.java | 1 + .../TransientOverrideAsPersistentJoined.java | 2 + ...ientOverrideAsPersistentTablePerClass.java | 2 + .../jdbc/internal/BasicConnectionTest.java | 3 + .../proxy/ProxyReferenceEqualityTest.java | 4 +- .../test/quote/TableGeneratorQuotingTest.java | 29 ++--- .../TestExtraPhysicalTableTypes.java | 88 +++++++++++---- .../PostgreSQLMultipleSchemaSequenceTest.java | 9 +- .../SchemaMigratorHaltOnErrorTest.java | 2 + .../SchemaUpdateHaltOnErrorTest.java | 3 + .../LongVarcharValidationTest.java | 16 +-- ...calDateCustomSessionLevelTimeZoneTest.java | 2 - .../test/type/AbstractJavaTimeTypeTest.java | 37 +++--- ...reparedStatementSpyConnectionProvider.java | 8 +- .../hibernate/query/hhh12225/Vehicle.hbm.xml | 2 +- .../cache/ehcache/test/TestHelper.java | 2 +- .../collection/StringMapLobTest.java | 4 + .../StringMapNationalizedLobTest.java | 4 + .../tools/OrderSequenceGenerationTest.java | 5 +- ...reparedStatementSpyConnectionProvider.java | 8 +- .../jcache/test/RefreshUpdatedDataTest.java | 4 +- .../org/hibernate/jcache/test/TestHelper.java | 2 +- .../org/hibernate/testing/DialectChecks.java | 7 ++ .../testing/transaction/TransactionUtil.java | 56 ++++++++++ 80 files changed, 628 insertions(+), 185 deletions(-) diff --git a/.github/workflows/contributor-build.yml b/.github/workflows/contributor-build.yml index 9a2e885e05..966e5a3011 100644 --- a/.github/workflows/contributor-build.yml +++ b/.github/workflows/contributor-build.yml @@ -72,7 +72,9 @@ jobs: if: failure() with: name: test-reports-java8-${{ matrix.rdbms }} - path: './**/target/reports/tests/test/' + path: | + ./**/target/reports/tests/ + ./**/target/reports/checkstyle/ - name: Omit produced artifacts from build cache run: ./ci/before-cache.sh build11: @@ -109,6 +111,8 @@ jobs: if: failure() with: name: test-reports-java11 - path: './**/target/reports/tests/test/' + path: | + ./**/target/reports/tests/ + ./**/target/reports/checkstyle/ - name: Omit produced artifacts from build cache run: ./ci/before-cache.sh \ No newline at end of file diff --git a/ci/build-github.sh b/ci/build-github.sh index 611aecd98b..281feed19c 100755 --- a/ci/build-github.sh +++ b/ci/build-github.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" java -version -./gradlew assemble + if [ "$RDBMS" == 'mysql' ]; then bash $DIR/../docker_db.sh mysql_5_7 elif [ "$RDBMS" == 'mysql8' ]; then diff --git a/ci/build-travis.sh b/ci/build-travis.sh index d1b5d38480..603396112b 100755 --- a/ci/build-travis.sh +++ b/ci/build-travis.sh @@ -3,7 +3,7 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" java -version -./gradlew assemble + if [ "$RDBMS" == 'mysql' ]; then sudo service mysql stop bash $DIR/../docker_db.sh mysql_5_7 diff --git a/ci/build.sh b/ci/build.sh index 704faaceb0..5a72ba2a45 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -4,15 +4,15 @@ goal= if [ "$RDBMS" == "derby" ]; then goal="-Pdb=derby" elif [ "$RDBMS" == "mariadb" ]; then - goal="-Pdb=mariadb" + goal="-Pdb=mariadb_ci" elif [ "$RDBMS" == "postgresql" ]; then - goal="-Pdb=pgsql" + goal="-Pdb=pgsql_ci" elif [ "$RDBMS" == "oracle" ]; then - goal="-Pdb=oracle -Dhibernate.connection.url=jdbc:oracle:thin:@localhost:1521:XE -Dhibernate.connection.username=SYSTEM -Dhibernate.connection.password=Oracle18" + goal="-Pdb=oracle_ci" elif [ "$RDBMS" == "db2" ]; then - goal="-Pdb=db2 -Dhibernate.connection.url=jdbc:db2://localhost:50000/orm_test -Dhibernate.connection.username=orm_test -Dhibernate.connection.password=orm_test" + goal="-Pdb=db2_ci" elif [ "$RDBMS" == "mssql" ]; then - goal="-Pdb=mssql -Dhibernate.connection.url=jdbc:sqlserver://localhost:1433;databaseName= -Dhibernate.connection.username=sa -Dhibernate.connection.password=hibernate_orm_test" + goal="-Pdb=mssql_ci" fi exec ./gradlew check ${goal} -Plog-test-progress=true --stacktrace \ No newline at end of file diff --git a/docker_db.sh b/docker_db.sh index 15a052e6d9..772baee82d 100755 --- a/docker_db.sh +++ b/docker_db.sh @@ -12,7 +12,7 @@ mysql_8_0() { mariadb() { docker rm -f mariadb || true - docker run --name mariadb -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -p3306:3306 -d mariadb:10.5.8 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci + docker run --name mariadb -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -p3306:3306 -d mariadb:10.5.8 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci } postgresql_9_5() { @@ -22,10 +22,10 @@ postgresql_9_5() { db2() { docker rm -f db2 || true - docker run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -p 50000:50000 -d ibmcom/db2:11.5.0.0a + docker run --name db2 --privileged -e DB2INSTANCE=orm_test -e DB2INST1_PASSWORD=orm_test -e DBNAME=orm_test -e LICENSE=accept -e AUTOCONFIG=false -e ARCHIVE_LOGS=false -e TO_CREATE_SAMPLEDB=false -e REPODB=false -p 50000:50000 -d ibmcom/db2:11.5.5.0 # Give the container some time to start OUTPUT= - while [[ $OUTPUT != *"Setup has completed"* ]]; do + while [[ $OUTPUT != *"INSTANCE"* ]]; do echo "Waiting for DB2 to start..." sleep 10 OUTPUT=$(docker logs db2) @@ -35,7 +35,23 @@ db2() { mssql() { docker rm -f mssql || true - docker run --name mssql -d -p 1433:1433 -e "SA_PASSWORD=hibernate_orm_test" -e ACCEPT_EULA=Y microsoft/mssql-server-linux:2017-CU13 + docker run --name mssql -d -p 1433:1433 -e "SA_PASSWORD=Hibernate_orm_test" -e ACCEPT_EULA=Y microsoft/mssql-server-linux:2017-CU13 + sleep 5 + n=0 + until [ "$n" -ge 5 ] + do + # We need a database that uses a non-lock based MVCC approach + # https://github.com/microsoft/homebrew-mssql-release/issues/2#issuecomment-682285561 + docker exec mssql bash -c 'echo "create database hibernate_orm_test collate SQL_Latin1_General_CP1_CI_AS; alter database hibernate_orm_test set READ_COMMITTED_SNAPSHOT ON" | /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Hibernate_orm_test -i /dev/stdin' && break + echo "Waiting for SQL Server to start..." + n=$((n+1)) + sleep 5 + done + if [ "$n" -ge 5 ]; then + echo "SQL Server failed to start and configure after 25 seconds" + else + echo "SQL Server successfully started" + fi } oracle() { @@ -43,6 +59,32 @@ oracle() { # We need to use the defaults # SYSTEM/Oracle18 docker run --shm-size=1536m --name oracle -d -p 1521:1521 quillbuilduser/oracle-18-xe + until [ "`docker inspect -f {{.State.Health.Status}} oracle`" == "healthy" ]; + do + echo "Waiting for Oracle to start..." + sleep 10; + done + echo "Oracle successfully started" + # We increase file sizes to avoid online resizes as that requires lots of CPU which is restricted in XE + docker exec oracle bash -c "source /home/oracle/.bashrc; bash -c \" +cat < { //tag::hql-concat-function-example[] @@ -1312,6 +1314,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(SQLServerDialect.class) + @SkipForDialect(value = DerbyDialect.class, comment = "Comparisons between 'DATE' and 'TIMESTAMP' are not supported") public void test_hql_current_date_function_example() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::hql-current-date-function-example[] @@ -1383,6 +1386,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "See https://issues.apache.org/jira/browse/DERBY-2072") public void test_hql_cast_function_example() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::hql-cast-function-example[] @@ -1396,6 +1400,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support extract function") public void test_hql_extract_function_example() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::hql-extract-function-example[] @@ -1550,6 +1555,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Comparisons between 'DATE' and 'TIMESTAMP' are not supported") public void test_hql_collection_expressions_example_7() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::hql-collection-expressions-example[] @@ -1565,6 +1571,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Comparisons between 'DATE' and 'TIMESTAMP' are not supported") public void test_hql_collection_expressions_example_8() { doInJPA( this::entityManagerFactory, entityManager -> { //tag::hql-collection-expressions-example[] diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobCharArrayTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobCharArrayTest.java index a5110d5f8b..50fa6a64d2 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobCharArrayTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobCharArrayTest.java @@ -11,6 +11,7 @@ import javax.persistence.Id; import javax.persistence.Lob; import org.hibernate.annotations.Nationalized; +import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -27,9 +28,10 @@ import static org.junit.Assert.assertArrayEquals; @SkipForDialect( value = { PostgreSQL81Dialect.class, - MySQL5Dialect.class + MySQL5Dialect.class, + DB2Dialect.class }, - comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695" + comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695 and https://hibernate.atlassian.net/browse/HHH-10473" ) public class NClobCharArrayTest extends BaseEntityManagerFunctionalTestCase { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobStringTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobStringTest.java index 561d392284..03d20f9234 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobStringTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobStringTest.java @@ -11,6 +11,7 @@ import javax.persistence.Id; import javax.persistence.Lob; import org.hibernate.annotations.Nationalized; +import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -27,9 +28,10 @@ import static org.junit.Assert.assertEquals; @SkipForDialect( value = { PostgreSQL81Dialect.class, - MySQL5Dialect.class + MySQL5Dialect.class, + DB2Dialect.class }, - comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695" + comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695 and https://hibernate.atlassian.net/browse/HHH-10473" ) public class NClobStringTest extends BaseEntityManagerFunctionalTestCase { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobTest.java index 6ec4103cd2..8061589e42 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NClobTest.java @@ -19,6 +19,7 @@ import org.hibernate.Session; import org.hibernate.annotations.Nationalized; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.CockroachDB192Dialect; +import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.MySQL5Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.engine.jdbc.NClobProxy; @@ -39,9 +40,10 @@ import static org.junit.Assert.fail; PostgreSQL81Dialect.class, MySQL5Dialect.class, AbstractHANADialect.class, - CockroachDB192Dialect.class + CockroachDB192Dialect.class, + DB2Dialect.class }, - comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695" + comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and https://hibernate.atlassian.net/browse/HHH-10695 and https://hibernate.atlassian.net/browse/HHH-10473" ) public class NClobTest extends BaseEntityManagerFunctionalTestCase { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NationalizedTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NationalizedTest.java index 5a7cb3f6dd..22ba662aa2 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NationalizedTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/NationalizedTest.java @@ -10,6 +10,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import org.hibernate.annotations.Nationalized; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -24,9 +25,10 @@ import static org.junit.Assert.assertEquals; */ @SkipForDialect( value = { - PostgreSQL81Dialect.class + PostgreSQL81Dialect.class, + DerbyDialect.class }, - comment = "@see https://hibernate.atlassian.net/browse/HHH-10693" + comment = "@see https://hibernate.atlassian.net/browse/HHH-10693 and Derby doesn't support nationalized type" ) public class NationalizedTest extends BaseEntityManagerFunctionalTestCase { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/SubselectTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/SubselectTest.java index 447cfbb9fa..d64f14813f 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/SubselectTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/SubselectTest.java @@ -15,8 +15,10 @@ import javax.persistence.Table; import org.hibernate.annotations.Subselect; import org.hibernate.annotations.Synchronize; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.SkipForDialect; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; @@ -25,6 +27,7 @@ import static org.junit.Assert.assertEquals; /** * @author Vlad Mihalcea */ +@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support a CONCAT function") public class SubselectTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TypeCategoryTest.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TypeCategoryTest.java index d3aae6afa3..7ec10e9e01 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TypeCategoryTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TypeCategoryTest.java @@ -59,11 +59,11 @@ public class TypeCategoryTest extends BaseEntityManagerFunctionalTestCase { @Embeddable public class Name { - private String first; + private String firstName; - private String middle; + private String middleName; - private String last; + private String lastName; // getters and setters omitted } diff --git a/gradle/databases.gradle b/gradle/databases.gradle index aec10c7067..d7fdcedfac 100644 --- a/gradle/databases.gradle +++ b/gradle/databases.gradle @@ -8,6 +8,7 @@ // build a map of the database settings to use. ext { db = project.hasProperty('db') ? project.getProperty('db') : 'h2' + def dbHost = System.getProperty( 'dbHost', 'localhost' ) dbBundle = [ h2 : [ 'db.dialect' : 'org.hibernate.dialect.H2Dialect', @@ -42,7 +43,16 @@ ext { 'jdbc.driver': 'org.postgresql.Driver', 'jdbc.user' : 'hibernate_orm_test', 'jdbc.pass' : 'hibernate_orm_test', - 'jdbc.url' : 'jdbc:postgresql://127.0.0.1/hibernate_orm_test' + // Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com + 'jdbc.url' : 'jdbc:postgresql://127.0.0.1/hibernate_orm_test?preparedStatementCacheQueries=0' + ], + pgsql_ci : [ + 'db.dialect' : 'org.hibernate.dialect.PostgreSQL95Dialect', + 'jdbc.driver': 'org.postgresql.Driver', + 'jdbc.user' : 'hibernate_orm_test', + 'jdbc.pass' : 'hibernate_orm_test', + // Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com + 'jdbc.url' : 'jdbc:postgresql://' + dbHost + '/hibernate_orm_test?preparedStatementCacheQueries=0' ], mysql : [ 'db.dialect' : 'org.hibernate.dialect.MySQL57Dialect', @@ -65,6 +75,13 @@ ext { 'jdbc.pass' : 'hibernate_orm_test', 'jdbc.url' : 'jdbc:mariadb://127.0.0.1/hibernate_orm_test' ], + mariadb_ci : [ + 'db.dialect' : 'org.hibernate.dialect.MariaDB103Dialect', + 'jdbc.driver': 'org.mariadb.jdbc.Driver', + 'jdbc.user' : 'root', + 'jdbc.pass' : 'hibernate_orm_test', + 'jdbc.url' : 'jdbc:mariadb://' + dbHost + '/hibernate_orm_test' + ], postgis : [ 'db.dialect' : 'org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect', 'jdbc.driver': 'org.postgresql.Driver', @@ -89,6 +106,13 @@ ext { 'jdbc.pass' : 'Oradoc_db1', 'jdbc.url' : 'jdbc:oracle:thin:@localhost:1521:ORCLCDB' ], + oracle_ci : [ + 'db.dialect' : 'org.hibernate.dialect.Oracle12cDialect', + 'jdbc.driver': 'oracle.jdbc.OracleDriver', + 'jdbc.user' : 'SYSTEM', + 'jdbc.pass' : 'Oracle18', + 'jdbc.url' : 'jdbc:oracle:thin:@' + dbHost + ':1521:XE' + ], mssql : [ 'db.dialect' : 'org.hibernate.dialect.SQLServer2012Dialect', 'jdbc.driver': 'com.microsoft.sqlserver.jdbc.SQLServerDriver', @@ -96,6 +120,13 @@ ext { 'jdbc.pass' : 'hibernate_orm_test', 'jdbc.url' : 'jdbc:sqlserver://localhost;instance=SQLEXPRESS;databaseName=hibernate_orm_test' ], + mssql_ci : [ + 'db.dialect' : 'org.hibernate.dialect.SQLServer2012Dialect', + 'jdbc.driver': 'com.microsoft.sqlserver.jdbc.SQLServerDriver', + 'jdbc.user' : 'sa', + 'jdbc.pass' : 'Hibernate_orm_test', + 'jdbc.url' : 'jdbc:sqlserver://' + dbHost + ';databaseName=hibernate_orm_test' + ], informix : [ 'db.dialect' : 'org.hibernate.dialect.InformixDialect', 'jdbc.driver': 'com.informix.jdbc.IfxDriver', @@ -110,6 +141,13 @@ ext { 'jdbc.pass' : 'db2inst1-pwd', 'jdbc.url' : 'jdbc:db2://127.0.0.1:50000/hibern8' ], + db2_ci : [ + 'db.dialect' : 'org.hibernate.dialect.DB2Dialect', + 'jdbc.driver': 'com.ibm.db2.jcc.DB2Driver', + 'jdbc.user' : 'orm_test', + 'jdbc.pass' : 'orm_test', + 'jdbc.url' : 'jdbc:db2://' + dbHost + ':50000/orm_test' + ], hana : [ 'db.dialect' : 'org.hibernate.dialect.HANAColumnStoreDialect', 'jdbc.driver': 'com.sap.db.jdbc.Driver', @@ -137,7 +175,8 @@ ext { 'jdbc.driver': 'org.postgresql.Driver', 'jdbc.user' : 'root', 'jdbc.pass' : '', - 'jdbc.url' : 'jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable' + // Disable prepared statement caching due to https://www.postgresql.org/message-id/CAEcMXhmmRd4-%2BNQbnjDT26XNdUoXdmntV9zdr8%3DTu8PL9aVCYg%40mail.gmail.com + 'jdbc.url' : 'jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&preparedStatementCacheQueries=0' ], ] } diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 819ec22d65..4a3066d790 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -78,6 +78,7 @@ dependencies { //Databases testRuntime( libraries.h2 ) + testRuntime( libraries.derby ) testRuntime( libraries.hsqldb ) testRuntime( libraries.postgresql ) testRuntime( libraries.mysql ) @@ -89,13 +90,15 @@ dependencies { asciidoclet 'org.asciidoctor:asciidoclet:1.+' - if ( db.equalsIgnoreCase( 'oracle' ) || db.equalsIgnoreCase( 'oracle_docker' ) ) { - testRuntime( libraries.oracle ) - } - else if ( db.equalsIgnoreCase( 'db2' ) ) { + testRuntime( libraries.oracle ) + + // Since both the DB2 driver and HANA have a package "net.jpountz" we have to add dependencies conditionally + // This is due to the "no split-packages" requirement of Java 9+ + + if ( db.startsWith( 'db2' ) ) { testRuntime( libraries.db2 ) } - else if ( db.equalsIgnoreCase( 'hana' ) ) { + else if ( db.startsWith( 'hana' ) ) { testRuntime( libraries.hana ) } diff --git a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/util/PreparedStatementSpyConnectionProvider.java b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/util/PreparedStatementSpyConnectionProvider.java index 43b8ba31e8..1f9025f42a 100644 --- a/hibernate-agroal/src/test/java/org/hibernate/test/agroal/util/PreparedStatementSpyConnectionProvider.java +++ b/hibernate-agroal/src/test/java/org/hibernate/test/agroal/util/PreparedStatementSpyConnectionProvider.java @@ -53,7 +53,7 @@ public class PreparedStatementSpyConnectionProvider extends AgroalConnectionProv public void closeConnection(Connection conn) throws SQLException { acquiredConnections.remove( conn ); releasedConnections.add( conn ); - super.closeConnection( conn ); + super.closeConnection( (Connection) MockUtil.getMockSettings( conn ).getSpiedInstance() ); } @Override diff --git a/hibernate-c3p0/src/test/resources/hibernate.properties b/hibernate-c3p0/src/test/resources/hibernate.properties index 332d78bd38..0d39da782e 100644 --- a/hibernate-c3p0/src/test/resources/hibernate.properties +++ b/hibernate-c3p0/src/test/resources/hibernate.properties @@ -22,6 +22,7 @@ hibernate.c3p0.testConnectionOnCheckout true hibernate.show_sql false hibernate.max_fetch_depth 5 +hibernate.connection.provider_class C3P0ConnectionProvider hibernate.cache.region_prefix hibernate.test hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java index ad2681a4b6..38fe222790 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DB2Dialect.java @@ -583,7 +583,7 @@ public class DB2Dialect extends Dialect { nullPrecedence == NullPrecedence.FIRST ? "0" : "1", nullPrecedence == NullPrecedence.FIRST ? "1" : "0", expression, - order + order == null ? "asc" : order ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index 421a8085dd..9b4764df94 100755 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -608,4 +608,9 @@ public class DerbyDialect extends DB2Dialect { } }, AfterUseAction.CLEAN, null); } + + @Override + public boolean supportsPartitionBy() { + return false; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java index f95ef92872..a2e0de9dca 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDB103Dialect.java @@ -9,6 +9,7 @@ package org.hibernate.dialect; import java.time.Duration; import org.hibernate.LockOptions; +import org.hibernate.MappingException; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorMariaDBDatabaseImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; @@ -42,6 +43,22 @@ public class MariaDB103Dialect extends MariaDB102Dialect { return "create sequence " + sequenceName; } + @Override + protected String getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) + throws MappingException { + final String sequenceString = getCreateSequenceString( sequenceName ) + " start with " + initialValue + " increment by " + incrementSize; + // MariaDB has defaults for min and max value that don't play well with settings then sign( increment ) != sign( initialValue ) + if ( incrementSize > 0 && initialValue < 0 ) { + return sequenceString + " minvalue " + initialValue; + } + else if ( incrementSize < 0 && initialValue > 0 ) { + return sequenceString + " maxvalue " + initialValue; + } + else { + return sequenceString; + } + } + @Override public String getDropSequenceString(String sequenceName) { return "drop sequence " + sequenceName; diff --git a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java index 930da89d34..71f4e76395 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/spi/id/AbstractMultiTableBulkIdStrategyImpl.java @@ -55,7 +55,7 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl { diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java index 28486f5162..6537ad7b5e 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/selectcase/SelectCaseTest.java @@ -35,6 +35,7 @@ import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; @@ -45,6 +46,7 @@ import org.junit.Test; @TestForIssue( jiraKey = "HHH-9731" ) @SkipForDialect(value = DB2Dialect.class, comment = "We would need casts in the case clauses. See HHH-12822.") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby requires either casted parameters or literals in the result arms of CASE expressions") public class SelectCaseTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Translation.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Translation.java index dc54bf1613..1ab70f659b 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Translation.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metamodel/Translation.java @@ -8,11 +8,13 @@ package org.hibernate.jpa.test.metamodel; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; /** * @author Steve Ebersole */ @Entity +@Table(name = "translation_tbl") public class Translation { @Id Integer id; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/QueryTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/QueryTest.java index 786c7c3ce1..dc0090ac42 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/query/QueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/query/QueryTest.java @@ -26,6 +26,7 @@ import org.hibernate.Hibernate; import org.hibernate.QueryException; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.CockroachDB192Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.PostgreSQL9Dialect; import org.hibernate.dialect.PostgresPlusDialect; @@ -136,6 +137,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullPositionalParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -166,6 +168,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullPositionalParameterParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -213,6 +216,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullPositionalParameterParameterIncompatible() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -260,6 +264,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullNamedParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -290,6 +295,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullNamedParameterParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -336,6 +342,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Test @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testNullNamedParameterParameterIncompatible() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -386,6 +393,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to INTEGER") public void testNativeQueryNullPositionalParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -423,6 +431,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to INTEGER") public void testNativeQueryNullPositionalParameterParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -476,6 +485,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to INTEGER") public void testNativeQueryNullNamedParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); @@ -513,6 +523,7 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = Oracle8iDialect.class, comment = "ORA-00932: inconsistent datatypes: expected NUMBER got BINARY") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to INTEGER") public void testNativeQueryNullNamedParameterParameter() throws Exception { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/schemagen/JpaSchemaGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/schemagen/JpaSchemaGeneratorTest.java index 7fde17a6aa..8ebb3cbb80 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/schemagen/JpaSchemaGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/schemagen/JpaSchemaGeneratorTest.java @@ -49,7 +49,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase @TestForIssue(jiraKey = "HHH-8271") public void testSqlLoadScriptSourceClasspath() throws Exception { Map settings = buildSettings(); - settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create" ); + settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getLoadSqlScript() ); doTest( settings ); } @@ -60,7 +60,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase @TestForIssue(jiraKey = "HHH-8271") public void testSqlLoadScriptSourceUrl() throws Exception { Map settings = buildSettings(); - settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create" ); + settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getResourceUrlString( getLoadSqlScript() ) ); doTest( settings ); } @@ -78,7 +78,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase @TestForIssue(jiraKey = "HHH-8271") public void testSqlCreateScriptSourceClasspath() throws Exception { Map settings = buildSettings(); - settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create" ); + settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getCreateSqlScript() ); doTest( settings ); @@ -89,7 +89,7 @@ public class JpaSchemaGeneratorTest extends BaseEntityManagerFunctionalTestCase @TestForIssue(jiraKey = "HHH-8271") public void testSqlCreateScriptSourceUrl() throws Exception { Map settings = buildSettings(); - settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create" ); + settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getResourceUrlString( getCreateSqlScript() ) ); doTest( settings ); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/FlushAndTransactionTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/FlushAndTransactionTest.java index 1037e9940b..6d7344945f 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/FlushAndTransactionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/FlushAndTransactionTest.java @@ -165,6 +165,11 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase catch ( IllegalStateException e ) { //success } + finally { + if ( em.getTransaction().isActive() ) { + em.getTransaction().rollback(); + } + } } @Test diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/batch/JtaWithFailingBatchTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/batch/JtaWithFailingBatchTest.java index ee38b55626..71fb84cd75 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/batch/JtaWithFailingBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/transaction/batch/JtaWithFailingBatchTest.java @@ -75,8 +75,10 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest { } catch (Exception expected) { //expected - if ( transactionManager.getStatus() == Status.STATUS_ACTIVE ) { - transactionManager.rollback(); + switch ( transactionManager.getStatus() ) { + case Status.STATUS_ACTIVE: + case Status.STATUS_MARKED_ROLLBACK: + transactionManager.rollback(); } } @@ -89,7 +91,6 @@ public class JtaWithFailingBatchTest extends AbstractJtaBatchTest { assertStatementsListIsCleared(); } finally { - em.close(); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/BasicCriteriaExecutionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/BasicCriteriaExecutionTests.java index 7f60350004..d463407546 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/BasicCriteriaExecutionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/BasicCriteriaExecutionTests.java @@ -14,6 +14,9 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.ParameterExpression; import javax.persistence.criteria.Root; +import org.hibernate.dialect.DerbyDialect; + +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; @@ -92,6 +95,7 @@ public class BasicCriteriaExecutionTests extends BaseNonConfigCoreFunctionalTest } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other") public void testExecutingBasicCriteriaQueryParameterPredicate() { final CriteriaBuilder criteriaBuilder = sessionFactory().getCriteriaBuilder(); @@ -111,6 +115,7 @@ public class BasicCriteriaExecutionTests extends BaseNonConfigCoreFunctionalTest } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other") public void testExecutingBasicCriteriaQueryParameterPredicateInStatelessSession() { final CriteriaBuilder criteriaBuilder = sessionFactory().getCriteriaBuilder(); diff --git a/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/expression/SearchedCaseExpressionTest.java b/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/expression/SearchedCaseExpressionTest.java index c92d60c619..0590ecdea8 100644 --- a/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/expression/SearchedCaseExpressionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/expression/SearchedCaseExpressionTest.java @@ -19,6 +19,7 @@ import javax.persistence.criteria.Path; import javax.persistence.criteria.Root; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; @@ -65,6 +66,7 @@ public class SearchedCaseExpressionTest extends BaseCoreFunctionalTestCase { @Test @SkipForDialect(value = DB2Dialect.class, comment = "We would need casts in the case clauses. See HHH-12822.") + @SkipForDialect(value = DerbyDialect.class, comment = "Derby requires either casted parameters or literals in the result arms of CASE expressions") public void testEqualClause() { doInHibernate( this::sessionFactory, session -> { CriteriaBuilder cb = session.getCriteriaBuilder(); @@ -89,6 +91,8 @@ public class SearchedCaseExpressionTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-13167") + @SkipForDialect(value = DB2Dialect.class, comment = "We would need casts in the case clauses. See HHH-12822.") + @SkipForDialect(value = DerbyDialect.class, comment = "Derby requires either casted parameters or literals in the result arms of CASE expressions") public void testMissingElseClause() { doInHibernate( this::sessionFactory, session -> { Event event = new Event(); diff --git a/hibernate-core/src/test/java/org/hibernate/query/hhh14156/HHH14156Test.java b/hibernate-core/src/test/java/org/hibernate/query/hhh14156/HHH14156Test.java index 48bc7cb191..bb943030b2 100644 --- a/hibernate-core/src/test/java/org/hibernate/query/hhh14156/HHH14156Test.java +++ b/hibernate-core/src/test/java/org/hibernate/query/hhh14156/HHH14156Test.java @@ -7,6 +7,10 @@ import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.SQLServerDialect; + +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -24,6 +28,8 @@ public class HHH14156Test extends BaseCoreFunctionalTestCase { } @Test + @SkipForDialect(value = SQLServerDialect.class, comment = "SQLServer doesn't support tuple comparisons") + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support tuple comparisons") public void testNoExceptionThrown() { inTransaction( session -> session.createQuery( diff --git a/hibernate-core/src/test/java/org/hibernate/secure/JaccIntegratorTest.java b/hibernate-core/src/test/java/org/hibernate/secure/JaccIntegratorTest.java index f3e0f7eadd..e27160755a 100644 --- a/hibernate-core/src/test/java/org/hibernate/secure/JaccIntegratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/secure/JaccIntegratorTest.java @@ -161,7 +161,7 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase { } } - @Entity + @Entity(name = "Person") public static class Person { @Id diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java index ee345f5442..f354a95d9e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/EmbeddableWithOneToMany_HHH_11302_xml_Test.java @@ -33,6 +33,7 @@ public class EmbeddableWithOneToMany_HHH_11302_xml_Test extends }; } + @Override public void buildEntityManagerFactory() { try { super.buildEntityManagerFactory(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/hhh4635/LobTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/hhh4635/LobTest.java index 2db8952ec0..bfafb985f9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/hhh4635/LobTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/lob/hhh4635/LobTest.java @@ -36,6 +36,7 @@ public class LobTest extends BaseCoreFunctionalTestCase { entity.setQwerty(randomString(4000)); session.save(entity); session.getTransaction().commit(); + session.close(); } @Override @@ -60,5 +61,7 @@ public class LobTest extends BaseCoreFunctionalTestCase { String s = (String) query.uniqueResult(); log.debug( "Using Oracle charset " + s ); + session.getTransaction().commit(); + session.close(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java index 3bf94bf67d..a11b3e8e8c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/query/QueryAndSQLTest.java @@ -24,6 +24,7 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.CockroachDB192Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.PostgreSQL9Dialect; @@ -121,6 +122,7 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase { @SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to BIGINT") public void testQueryWithNullParameter(){ Chaos c0 = new Chaos(); c0.setId( 0L ); @@ -207,6 +209,7 @@ public class QueryAndSQLTest extends BaseCoreFunctionalTestCase { @SkipForDialect(value = PostgresPlusDialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = CockroachDB192Dialect.class, jiraKey = "HHH-10312", comment = "Cannot convert untyped null (assumed to be bytea type) to bigint") @SkipForDialect(value = SybaseDialect.class, comment = "Null == null on Sybase") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to BIGINT") public void testNativeQueryWithNullParameter(){ Chaos c0 = new Chaos(); c0.setId( 0L ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bulkid/GlobalTemporaryTableBulkCompositeIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/bulkid/GlobalTemporaryTableBulkCompositeIdTest.java index 56cbfe9922..97a3486179 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bulkid/GlobalTemporaryTableBulkCompositeIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bulkid/GlobalTemporaryTableBulkCompositeIdTest.java @@ -1,18 +1,15 @@ package org.hibernate.test.bulkid; -import org.hibernate.dialect.CockroachDB192Dialect; -import org.hibernate.dialect.PostgreSQL82Dialect; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.SkipForDialect; +import org.hibernate.testing.DialectChecks; +import org.hibernate.testing.RequiresDialectFeature; /** * @author Vlad Mihalcea */ -@RequiresDialect(PostgreSQL82Dialect.class) -@SkipForDialect(value = CockroachDB192Dialect.class, comment = "https://github.com/cockroachdb/cockroach/issues/5807") +@RequiresDialectFeature(DialectChecks.SupportsGlobalTemporaryTables.class) public class GlobalTemporaryTableBulkCompositeIdTest extends AbstractBulkCompositeIdTest { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/cascade/MergeTest.java b/hibernate-core/src/test/java/org/hibernate/test/cascade/MergeTest.java index f17aabd3ba..d2278e6124 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cascade/MergeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cascade/MergeTest.java @@ -14,6 +14,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Table; import org.junit.Test; @@ -102,7 +103,8 @@ public class MergeTest extends BaseCoreFunctionalTestCase { }; } - @Entity + @Entity(name = "Order") + @Table(name = "orders") private static class Order { @Id @GeneratedValue @@ -120,7 +122,7 @@ public class MergeTest extends BaseCoreFunctionalTestCase { } } - @Entity + @Entity(name = "Item") private static class Item { @Id @GeneratedValue diff --git a/hibernate-core/src/test/java/org/hibernate/test/cdi/converters/legacy/QueryTest.java b/hibernate-core/src/test/java/org/hibernate/test/cdi/converters/legacy/QueryTest.java index a92fad7ff7..6b5615770a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cdi/converters/legacy/QueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cdi/converters/legacy/QueryTest.java @@ -178,17 +178,17 @@ public class QueryTest extends BaseEntityManagerFunctionalTestCase { @Embeddable public static class Name { - public String first; - public String middle; - public String last; + public String firstName; + public String middleName; + public String lastName; public Name() { } - public Name(String first, String middle, String last) { - this.first = first; - this.middle = middle; - this.last = last; + public Name(String firstName, String middleName, String lastName) { + this.firstName = firstName; + this.middleName = middleName; + this.lastName = lastName; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/BeforeCompletionReleaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/connections/BeforeCompletionReleaseTest.java index 4d50804aef..365dd3cdc4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/BeforeCompletionReleaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/BeforeCompletionReleaseTest.java @@ -135,6 +135,7 @@ public class BeforeCompletionReleaseTest extends BaseEntityManagerFunctionalTest inOrder.verify( statementMock ).close(); inOrder.verify( connectionSpy ).close(); inOrder.verify( transactionSpy ).commit( any(), anyBoolean() ); + Mockito.reset( connectionSpy ); } private void spyOnTransaction(XAResource xaResource) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionsReleaseAutoCommitTest.java b/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionsReleaseAutoCommitTest.java index 00ec9be69f..7f868348cb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionsReleaseAutoCommitTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/ConnectionsReleaseAutoCommitTest.java @@ -27,6 +27,9 @@ import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.MockUtil; + import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.spy; @@ -92,6 +95,7 @@ public class ConnectionsReleaseAutoCommitTest extends BaseEntityManagerFunctiona assertEquals( 1, connectionProvider.getConnectionCount() ); verify( connectionProvider.connection, times( 1 ) ).close(); + Mockito.reset( connectionProvider.connection ); } @Entity(name = "Thing") diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/AndNationalizedTests.java b/hibernate-core/src/test/java/org/hibernate/test/converter/AndNationalizedTests.java index d80a45cba9..05c58515b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/AndNationalizedTests.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/AndNationalizedTests.java @@ -20,8 +20,12 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.dialect.CockroachDB192Dialect; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.Dialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.mapping.PersistentClass; + +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; @@ -34,6 +38,7 @@ import static org.junit.Assert.assertEquals; * @author Steve Ebersole */ //@SkipForDialect(value = PostgreSQL81Dialect.class, comment = "Postgres does not support ") +@SkipForDialect(value = DB2Dialect.class, comment = "DB2 jdbc driver doesn't support setNString") public class AndNationalizedTests extends BaseUnitTestCase { @Test @TestForIssue( jiraKey = "HHH-9599") @@ -44,9 +49,10 @@ public class AndNationalizedTests extends BaseUnitTestCase { ( (MetadataImpl) metadata ).validate(); final PersistentClass entityBinding = metadata.getEntityBinding( TestEntity.class.getName() ); - if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect - || metadata.getDatabase().getDialect() instanceof DB2Dialect - || metadata.getDatabase().getDialect() instanceof CockroachDB192Dialect){ + final Dialect dialect = metadata.getDatabase().getDialect(); + if ( dialect instanceof PostgreSQL81Dialect + || dialect instanceof DB2Dialect && !( dialect instanceof DerbyDialect ) + || dialect instanceof CockroachDB192Dialect){ // See issue HHH-10693 for PostgreSQL and CockroachDB, HHH-12753 for DB2 assertEquals( Types.VARCHAR, diff --git a/hibernate-core/src/test/java/org/hibernate/test/criteria/InTest.java b/hibernate-core/src/test/java/org/hibernate/test/criteria/InTest.java index c520afab58..dc06b79740 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criteria/InTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criteria/InTest.java @@ -14,8 +14,11 @@ import java.util.List; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Restrictions; +import org.hibernate.dialect.DerbyDialect; + import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -50,6 +53,7 @@ public class InTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-8901" ) @RequiresDialectFeature(DialectChecks.NotSupportsEmptyInListCheck.class) + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't like `x in (null)`") public void testEmptyInListForDialectNotSupportsEmptyInList() { Session session = openSession(); Transaction tx = session.beginTransaction(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java index 7dff458e48..7f10541705 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criterion/NationalizedIgnoreCaseTest.java @@ -15,6 +15,7 @@ import org.hibernate.Criteria; import org.hibernate.annotations.Nationalized; import org.hibernate.criterion.Restrictions; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.testing.SkipForDialect; @@ -30,6 +31,7 @@ import static org.junit.Assert.assertEquals; */ @TestForIssue( jiraKey = "HHH-8657" ) @SkipForDialect(value = DB2Dialect.class, comment = "DB2 jdbc driver doesn't support setNString") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby jdbc driver doesn't support setNString") @SkipForDialect(value = PostgreSQL81Dialect.class, comment = "PostgreSQL jdbc driver doesn't support setNString") public class NationalizedIgnoreCaseTest extends BaseCoreFunctionalTestCase { diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java index adc7befadc..02eeb5602d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectCollationTest.java @@ -22,11 +22,14 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.SQLServer2005Dialect; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.service.ServiceRegistry; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.transaction.TransactionUtil; import org.junit.Test; import org.jboss.logging.Logger; @@ -55,19 +58,31 @@ public class SQLServerDialectCollationTest extends BaseCoreFunctionalTestCase { StandardServiceRegistryImpl _serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() ); try { - try (Connection connection = _serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection(); - Statement statement = connection.createStatement()) { - connection.setAutoCommit( true ); - statement.executeUpdate( "DROP DATABASE hibernate_orm_test_collation" ); + try { + TransactionUtil.doWithJDBC( + _serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + statement.executeUpdate( "DROP DATABASE hibernate_orm_test_collation" ); + } + } + ); } catch (SQLException e) { log.debug( e.getMessage() ); } - try (Connection connection = _serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection(); - Statement statement = connection.createStatement()) { - connection.setAutoCommit( true ); - statement.executeUpdate( "CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS" ); - statement.executeUpdate( "ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF " ); + try { + TransactionUtil.doWithJDBC( + _serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + statement.executeUpdate( "CREATE DATABASE hibernate_orm_test_collation COLLATE Latin1_General_CS_AS" ); + statement.executeUpdate( "ALTER DATABASE [hibernate_orm_test_collation] SET AUTO_CLOSE OFF " ); + } + } + ); } catch (SQLException e) { log.debug( e.getMessage() ); @@ -148,7 +163,6 @@ public class SQLServerDialectCollationTest extends BaseCoreFunctionalTestCase { } } - @Override protected boolean rebuildSessionFactoryOnError() { return false; diff --git a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java index 97e53d2f4f..0322f9284f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/dialect/functional/SQLServerDialectTempTableCollationTest.java @@ -6,7 +6,6 @@ */ package org.hibernate.test.dialect.functional; -import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -21,12 +20,12 @@ import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.SQLServer2005Dialect; -import org.hibernate.engine.jdbc.spi.JdbcServices; -import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.jdbc.SharedDriverManagerConnectionProviderImpl; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.transaction.TransactionUtil; import org.junit.Assert; import org.junit.Test; @@ -50,20 +49,34 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe return configuration; } - @AfterClassOnce - protected void revertBackOriginalDBCollation() { + @Override + protected void releaseSessionFactory() { + super.releaseSessionFactory(); if ( originalDBCollation != null && collationChanged && !changedDBCollation.equals( originalDBCollation ) ) { BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() ); - try (Connection connection = serviceRegistry.getService( JdbcServices.class ) - .getBootstrapJdbcConnectionAccess() - .obtainConnection(); - Statement statement = connection.createStatement()) { - connection.setAutoCommit( true ); - statement.executeUpdate( "ALTER DATABASE CURRENT COLLATE " + originalDBCollation ); + try { + TransactionUtil.doWithJDBC( + serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + String dbName; + try ( ResultSet rs = statement.executeQuery( "SELECT DB_NAME()" ) ) { + rs.next(); + dbName = rs.getString( 1 ); + } + statement.execute( "USE master" ); + statement.execute( "ALTER DATABASE " + dbName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE" ); + statement.executeUpdate( "ALTER DATABASE " + dbName + " COLLATE " + originalDBCollation ); + statement.execute( "ALTER DATABASE " + dbName + " SET MULTI_USER WITH ROLLBACK IMMEDIATE" ); + statement.execute( "USE " + dbName ); + } + } + ); } catch (SQLException e) { throw new RuntimeException( "Failed to revert back database collation to " + originalDBCollation, e ); @@ -72,42 +85,70 @@ public class SQLServerDialectTempTableCollationTest extends BaseCoreFunctionalTe serviceRegistry.destroy(); } } + // The alter database calls could lead to issues with existing connections, so we reset the shared pool here + SharedDriverManagerConnectionProviderImpl.getInstance().reset(); } + @Override protected void buildSessionFactory() { BootstrapServiceRegistry bootRegistry = buildBootstrapServiceRegistry(); StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, constructConfiguration() ); try { - try ( Connection connection = serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection(); - Statement statement = connection.createStatement() ) { - connection.setAutoCommit( true ); - try ( ResultSet rs = statement.executeQuery( "SELECT SERVERPROPERTY('collation')" ) ) { - rs.next(); - String instanceCollation = rs.getString( 1 ); - Assert.assertNotEquals( instanceCollation, changedDBCollation ); - } + try { + TransactionUtil.doWithJDBC( + serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + try ( ResultSet rs = statement.executeQuery( "SELECT DATABASEPROPERTYEX(DB_NAME(),'collation')" ) ) { + rs.next(); + String instanceCollation = rs.getString( 1 ); + Assert.assertNotEquals( instanceCollation, changedDBCollation ); + } + } + } + ); } catch (SQLException e) { log.debug( e.getMessage() ); } - try ( Connection connection = serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection(); - Statement statement = connection.createStatement() ) { - connection.setAutoCommit( true ); - try ( ResultSet rs = statement.executeQuery( "SELECT CONVERT (varchar(256), DATABASEPROPERTYEX(DB_NAME(),'collation'))" ) ) { - rs.next(); - originalDBCollation = rs.getString( 1 ); - } + try { + TransactionUtil.doWithJDBC( + serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + try ( ResultSet rs = statement.executeQuery( "SELECT CONVERT (varchar(256), DATABASEPROPERTYEX(DB_NAME(),'collation'))" ) ) { + rs.next(); + originalDBCollation = rs.getString( 1 ); + } + } + } + ); } catch (SQLException e) { log.debug( e.getMessage() ); } - try ( Connection connection = serviceRegistry.getService( JdbcServices.class ).getBootstrapJdbcConnectionAccess().obtainConnection(); - Statement statement = connection.createStatement() ) { - connection.setAutoCommit( true ); - statement.executeUpdate( "ALTER DATABASE CURRENT COLLATE " + changedDBCollation ); - collationChanged = true; - } + TransactionUtil.doWithJDBC( + serviceRegistry, + connection -> { + try (Statement statement = connection.createStatement()) { + connection.setAutoCommit( true ); + String dbName; + try ( ResultSet rs = statement.executeQuery( "SELECT DB_NAME()" ) ) { + rs.next(); + dbName = rs.getString( 1 ); + } + statement.execute( "USE master" ); + statement.execute( "ALTER DATABASE " + dbName + " SET SINGLE_USER WITH ROLLBACK IMMEDIATE" ); + statement.executeUpdate( "ALTER DATABASE " + dbName + " COLLATE " + changedDBCollation ); + statement.execute( "ALTER DATABASE " + dbName + " SET MULTI_USER WITH ROLLBACK IMMEDIATE" ); + statement.execute( "USE " + dbName ); + collationChanged = true; + } + } + ); } catch ( SQLException e ) { throw new RuntimeException( e ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java index 7763bd6f8a..e7aef34ef5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/fileimport/MultiLineImportFileTest.java @@ -62,7 +62,20 @@ public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase { final String multiLineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" ) .uniqueResult(); // "Multi-line comment line 1\n-- line 2'\n/* line 3 */" - final String expected = String.format( "Multi-line comment line 1%n-- line 2'%n/* line 3 */" ); + final String line1 = "Multi-line comment line 1"; + final String line2 = "-- line 2'"; + final String line3 = "/* line 3 */"; + final String lineSeparator; + if ( multiLineText.length() < line1.length() + 2 || multiLineText.charAt( line1.length() ) == '\n' ) { + lineSeparator = "\n"; + } + else if ( multiLineText.charAt( line1.length() + 1 ) == '\n' ) { + lineSeparator = "\r\n"; + } + else { + lineSeparator = "\r"; + } + final String expected = String.join( lineSeparator, line1, line2, line3 ); assertEquals( "Multi-line string inserted incorrectly", expected, multiLineText ); String empty = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 3" ).uniqueResult(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java index 2a85a8ed85..f0e7330dd3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java @@ -646,6 +646,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-8901" ) @RequiresDialectFeature(DialectChecks.NotSupportsEmptyInListCheck.class) + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't like `x in (null)`") public void testEmptyInListForDialectsNotSupportsEmptyInList() { Session session = openSession(); session.beginTransaction(); @@ -674,6 +675,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue( jiraKey = "HHH-2851") + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void testMultipleRefsToSameParam() { Session s = openSession(); s.beginTransaction(); @@ -1774,6 +1776,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-1830") + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testAggregatedJoinAlias() { Session s = openSession(); s.getTransaction().begin(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/CoalesceTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/CoalesceTest.java index 3903664a3e..75157a986d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/CoalesceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/CoalesceTest.java @@ -12,6 +12,7 @@ import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.query.Query; @@ -66,6 +67,7 @@ public class CoalesceTest extends BaseCoreFunctionalTestCase { @Test @SkipForDialect( jiraKey = "HHH-10463", value = PostgreSQL81Dialect.class) @SkipForDialect( jiraKey = "HHH-10463", value = Oracle8iDialect.class) + @SkipForDialect(value = DerbyDialect.class, comment = "Cannot convert untyped null (assumed to be VARBINARY type) to VARCHAR") public void HHH_10463_NullInCoalesce() { doInHibernate( this::sessionFactory, session -> { Query query = session.createQuery("from Person p where p.name = coalesce(:name, p.name) "); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java index 9e4dd41418..6801fc3b6b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/WithClauseTest.java @@ -16,7 +16,9 @@ import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -243,6 +245,7 @@ public class WithClauseTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-11401") + @SkipForDialect(value = DerbyDialect.class,comment = "Derby does not support cast from INTEGER to VARCHAR") public void testWithClauseAsSubqueryWithKeyAndOtherJoinReference() { TestData data = new TestData(); data.prepare(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/size/ManyToManySizeTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/size/ManyToManySizeTest.java index 371c570b59..22f5924a6b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/size/ManyToManySizeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/size/ManyToManySizeTest.java @@ -16,7 +16,9 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import org.hibernate.Hibernate; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.After; @@ -45,6 +47,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsCompoundSelectExpression() { doInHibernate( this::sessionFactory, @@ -73,6 +76,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsCtorSelectExpression() { doInHibernate( this::sessionFactory, @@ -102,6 +106,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionWithLeftJoin() { doInHibernate( this::sessionFactory, @@ -131,6 +136,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionWithInnerJoin() { doInHibernate( this::sessionFactory, @@ -156,6 +162,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionOfAliasWithInnerJoin() { doInHibernate( this::sessionFactory, @@ -181,6 +188,7 @@ public class ManyToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionExcludeEmptyCollection() { doInHibernate( this::sessionFactory, diff --git a/hibernate-core/src/test/java/org/hibernate/test/hql/size/OneToManySizeTest.java b/hibernate-core/src/test/java/org/hibernate/test/hql/size/OneToManySizeTest.java index b355ec9f4c..1643732acb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/hql/size/OneToManySizeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/hql/size/OneToManySizeTest.java @@ -17,7 +17,9 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import org.hibernate.Hibernate; +import org.hibernate.dialect.DerbyDialect; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.After; @@ -32,6 +34,7 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; public class OneToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpression() { doInHibernate( this::sessionFactory, @@ -61,6 +64,7 @@ public class OneToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionWithLeftJoin() { doInHibernate( this::sessionFactory, @@ -90,6 +94,7 @@ public class OneToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionWithInnerJoin() { doInHibernate( this::sessionFactory, @@ -115,6 +120,7 @@ public class OneToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionOfAliasWithInnerJoin() { doInHibernate( this::sessionFactory, @@ -140,6 +146,7 @@ public class OneToManySizeTest extends BaseNonConfigCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't see that the subquery is functionally dependent") public void testSizeAsSelectExpressionExcludeEmptyCollection() { doInHibernate( this::sessionFactory, diff --git a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/HiLoSequenceMismatchStrategyTest.java b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/HiLoSequenceMismatchStrategyTest.java index 5b950cf2b1..7593925325 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/HiLoSequenceMismatchStrategyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/idgen/enhanced/sequence/HiLoSequenceMismatchStrategyTest.java @@ -78,6 +78,7 @@ public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase for ( String createSequenceStatement : createSequenceStatements ) { statement.execute( createSequenceStatement ); } + connection.commit(); } catch (SQLException e) { fail( e.getMessage() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentJoined.java b/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentJoined.java index 0901121872..d9942e8bc8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentJoined.java +++ b/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentJoined.java @@ -6,6 +6,7 @@ */ package org.hibernate.test.inheritance; +import java.util.Comparator; import java.util.List; import javax.persistence.Column; import javax.persistence.ConstraintMode; @@ -85,6 +86,7 @@ public class TransientOverrideAsPersistentJoined extends BaseNonConfigCoreFuncti final List employees = session.createQuery( "from Employee", Employee.class ) .getResultList(); assertEquals( 2, employees.size() ); + employees.sort( Comparator.comparing( Employee::getName ) ); assertTrue( Editor.class.isInstance( employees.get( 0 ) ) ); assertTrue( Writer.class.isInstance( employees.get( 1 ) ) ); final Editor editor = (Editor) employees.get( 0 ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentTablePerClass.java b/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentTablePerClass.java index 68cbc5d209..a06849d271 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentTablePerClass.java +++ b/hibernate-core/src/test/java/org/hibernate/test/inheritance/TransientOverrideAsPersistentTablePerClass.java @@ -6,6 +6,7 @@ */ package org.hibernate.test.inheritance; +import java.util.Comparator; import java.util.List; import javax.persistence.Column; import javax.persistence.ConstraintMode; @@ -84,6 +85,7 @@ public class TransientOverrideAsPersistentTablePerClass extends BaseNonConfigCor final List employees = session.createQuery( "from Employee", Employee.class ) .getResultList(); assertEquals( 2, employees.size() ); + employees.sort( Comparator.comparing( Employee::getName ) ); assertTrue( Editor.class.isInstance( employees.get( 0 ) ) ); assertTrue( Writer.class.isInstance( employees.get( 1 ) ) ); final Editor editor = (Editor) employees.get( 0 ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java index 762bc1ead6..9c9fa089ba 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java @@ -16,10 +16,12 @@ import java.sql.Statement; import org.hibernate.JDBCException; import org.hibernate.Session; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.resource.jdbc.ResourceRegistry; +import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -50,6 +52,7 @@ public class BasicConnectionTest extends BaseCoreFunctionalTestCase { } @Test + @SkipForDialect(value = DerbyDialect.class,comment = "Derby can't drop tables that are still referred to from open ResultSets") public void testBasicJdbcUsage() throws JDBCException { Session session = openSession(); SessionImplementor sessionImpl = (SessionImplementor) session; diff --git a/hibernate-core/src/test/java/org/hibernate/test/proxy/ProxyReferenceEqualityTest.java b/hibernate-core/src/test/java/org/hibernate/test/proxy/ProxyReferenceEqualityTest.java index f645bf1e43..04f07e12b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/proxy/ProxyReferenceEqualityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/proxy/ProxyReferenceEqualityTest.java @@ -63,7 +63,7 @@ public class ProxyReferenceEqualityTest extends BaseCoreFunctionalTestCase { } ); } - @Entity + @Entity(name = "A") public static class A { @Id Long id; @@ -72,7 +72,7 @@ public class ProxyReferenceEqualityTest extends BaseCoreFunctionalTestCase { B b; } - @Entity + @Entity(name = "B") public static class B { @Id Long id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java b/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java index e6ef1a0a17..f87ea73575 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/quote/TableGeneratorQuotingTest.java @@ -61,23 +61,26 @@ public class TableGeneratorQuotingTest extends BaseUnitTestCase { final Metadata metadata = new MetadataSources( serviceRegistry ).addAnnotatedClass( TestEntity.class ).buildMetadata(); final ConnectionProvider connectionProvider = serviceRegistry.getService( ConnectionProvider.class ); - final GenerationTarget target = new GenerationTargetToDatabase( - new DdlTransactionIsolatorTestingImpl( - serviceRegistry, - new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( connectionProvider ) - ) + + final DdlTransactionIsolatorTestingImpl ddlTransactionIsolator = new DdlTransactionIsolatorTestingImpl( + serviceRegistry, + new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( connectionProvider ) ); - - new SchemaCreatorImpl( serviceRegistry ).doCreation( metadata, false, target ); - try { - new SchemaValidator().validate( metadata ); - } - catch (HibernateException e) { - fail( "The identifier generator table should have validated. " + e.getMessage() ); + final GenerationTarget target = new GenerationTargetToDatabase( ddlTransactionIsolator, false ); + try { + new SchemaCreatorImpl( serviceRegistry ).doCreation( metadata, false, target ); + new SchemaValidator().validate( metadata ); + } + catch (HibernateException e) { + fail( "The identifier generator table should have validated. " + e.getMessage() ); + } + finally { + new SchemaDropperImpl( serviceRegistry ).doDrop( metadata, false, target ); + } } finally { - new SchemaDropperImpl( serviceRegistry ).doDrop( metadata, false, target ); + ddlTransactionIsolator.release(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/schematools/TestExtraPhysicalTableTypes.java b/hibernate-core/src/test/java/org/hibernate/test/schematools/TestExtraPhysicalTableTypes.java index 9cd339cc76..6547c7adf3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schematools/TestExtraPhysicalTableTypes.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schematools/TestExtraPhysicalTableTypes.java @@ -51,53 +51,77 @@ public class TestExtraPhysicalTableTypes { @Test public void testAddOneExtraPhysicalTableType() throws Exception { buildMetadata( "BASE TABLE" ); - InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(); - - assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( true ) ); - assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator(); + try { + InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest( + ddlTransactionIsolator + ); + assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( true ) ); + assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + } + finally { + ddlTransactionIsolator.release(); + } } @Test public void testAddingMultipleExtraPhysicalTableTypes() throws Exception { buildMetadata( "BASE, BASE TABLE" ); - InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(); - - assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( true ) ); - assertThat( informationExtractor.isPhysicalTableType( "BASE" ), is( true ) ); - assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); - assertThat( informationExtractor.isPhysicalTableType( "TABLE 1" ), is( false ) ); + DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator(); + try { + InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest( + ddlTransactionIsolator + ); + assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( true ) ); + assertThat( informationExtractor.isPhysicalTableType( "BASE" ), is( true ) ); + assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + assertThat( informationExtractor.isPhysicalTableType( "TABLE 1" ), is( false ) ); + } + finally { + ddlTransactionIsolator.release(); + } } @Test public void testExtraPhysicalTableTypesPropertyEmptyStringValue() throws Exception { buildMetadata( " " ); - InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(); - - assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( false ) ); - assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator(); + try { + InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest( + ddlTransactionIsolator + ); + assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( false ) ); + assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + } + finally { + ddlTransactionIsolator.release(); + } } @Test public void testNoExtraPhysicalTabeTypesProperty() throws Exception { buildMetadata( null ); - InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest(); - - assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( false ) ); - assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + DdlTransactionIsolator ddlTransactionIsolator = buildDdlTransactionIsolator(); + try { + InformationExtractorJdbcDatabaseMetaDataImplTest informationExtractor = buildInformationExtractorJdbcDatabaseMetaDataImplTest( + ddlTransactionIsolator + ); + assertThat( informationExtractor.isPhysicalTableType( "BASE TABLE" ), is( false ) ); + assertThat( informationExtractor.isPhysicalTableType( "TABLE" ), is( true ) ); + } + finally { + ddlTransactionIsolator.release(); + } } - private InformationExtractorJdbcDatabaseMetaDataImplTest buildInformationExtractorJdbcDatabaseMetaDataImplTest() + private InformationExtractorJdbcDatabaseMetaDataImplTest buildInformationExtractorJdbcDatabaseMetaDataImplTest(DdlTransactionIsolator ddlTransactionIsolator) throws SQLException { Database database = metadata.getDatabase(); - final ConnectionProvider connectionProvider = ssr.getService( ConnectionProvider.class ); DatabaseInformation dbInfo = new DatabaseInformationImpl( ssr, database.getJdbcEnvironment(), - new DdlTransactionIsolatorTestingImpl( ssr, - new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( - connectionProvider ) - ), + ddlTransactionIsolator, database.getDefaultNamespace().getName() ); ExtractionContextImpl extractionContext = new ExtractionContextImpl( @@ -113,6 +137,14 @@ public class TestExtraPhysicalTableTypes { extractionContext ); } + private DdlTransactionIsolator buildDdlTransactionIsolator() { + final ConnectionProvider connectionProvider = ssr.getService( ConnectionProvider.class ); + return new DdlTransactionIsolatorTestingImpl( + ssr, + new JdbcEnvironmentInitiator.ConnectionProviderJdbcConnectionAccess( connectionProvider ) + ); + } + private void buildMetadata(String extraPhysicalTableTypes) { if ( extraPhysicalTableTypes == null ) { ssr = new StandardServiceRegistryBuilder().build(); @@ -128,8 +160,16 @@ public class TestExtraPhysicalTableTypes { } public class InformationExtractorJdbcDatabaseMetaDataImplTest extends InformationExtractorJdbcDatabaseMetaDataImpl { + + private final ExtractionContext extractionContext; + public InformationExtractorJdbcDatabaseMetaDataImplTest(ExtractionContext extractionContext) { super( extractionContext ); + this.extractionContext = extractionContext; + } + + public ExtractionContext getExtractionContext() { + return extractionContext; } public boolean isPhysicalTableType(String tableType) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/PostgreSQLMultipleSchemaSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/PostgreSQLMultipleSchemaSequenceTest.java index 03b5be468c..caa10efa48 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/PostgreSQLMultipleSchemaSequenceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/PostgreSQLMultipleSchemaSequenceTest.java @@ -98,8 +98,15 @@ public class PostgreSQLMultipleSchemaSequenceTest extends BaseUnitTestCase { fail(e.getMessage()); } + String existingUrl = (String) Environment.getProperties().get( AvailableSettings.URL ); + if ( existingUrl.indexOf( '?' ) == -1 ) { + existingUrl += "?"; + } + else { + existingUrl += "&"; + } StandardServiceRegistry ssr2 = new StandardServiceRegistryBuilder() - .applySetting( AvailableSettings.URL, Environment.getProperties().get(AvailableSettings.URL) + "?currentSchema=" + extraSchemaName ) + .applySetting( AvailableSettings.URL, existingUrl + "currentSchema=" + extraSchemaName ) .build(); try { diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaMigratorHaltOnErrorTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaMigratorHaltOnErrorTest.java index 9f753b41d1..2e4acd9792 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaMigratorHaltOnErrorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaMigratorHaltOnErrorTest.java @@ -16,6 +16,7 @@ import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.SkipForDialect; import org.hibernate.tool.schema.spi.SchemaManagementException; @@ -25,6 +26,7 @@ import org.junit.Test; * @author Vlad Mihalcea */ @SkipForDialect(value = DB2Dialect.class, comment = "DB2 is far more resistant to the reserved keyword usage. See HHH-12832.") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby is far more resistant to the reserved keyword usage.") public class SchemaMigratorHaltOnErrorTest extends BaseEntityManagerFunctionalTestCase { @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaUpdateHaltOnErrorTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaUpdateHaltOnErrorTest.java index a52c80d65e..dc8a7124d4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaUpdateHaltOnErrorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SchemaUpdateHaltOnErrorTest.java @@ -23,6 +23,8 @@ import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.dialect.DB2Dialect; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.junit4.CustomRunner; + +import org.hibernate.dialect.DerbyDialect; import org.hibernate.tool.hbm2ddl.SchemaUpdate; import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.spi.SchemaManagementException; @@ -36,6 +38,7 @@ import org.junit.runner.RunWith; * @author Gail Badner */ @SkipForDialect(value = DB2Dialect.class, comment = "DB2 is far more resistant to the reserved keyword usage. See HHH-12832.") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby is far more resistant to the reserved keyword usage.") @RunWith(CustomRunner.class) public class SchemaUpdateHaltOnErrorTest { diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/LongVarcharValidationTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/LongVarcharValidationTest.java index bd96d28c44..6218d9e8fb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/LongVarcharValidationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemavalidation/LongVarcharValidationTest.java @@ -12,6 +12,7 @@ import java.util.EnumSet; import java.util.Map; import javax.persistence.Entity; import javax.persistence.Id; +import javax.persistence.Table; import org.hibernate.annotations.Type; import org.hibernate.boot.MetadataSources; @@ -155,13 +156,14 @@ public class LongVarcharValidationTest implements ExecutionOptions { ); } -@Entity(name = "Translation") -public static class Translation { - @Id - public Integer id; - @Type(type = "text") - String text; -} + @Entity(name = "Translation") + @Table(name = "translation_tbl") + public static class Translation { + @Id + public Integer id; + @Type(type = "text") + String text; + } @Override public Map getConfigurationValues() { diff --git a/hibernate-core/src/test/java/org/hibernate/test/timestamp/LocalDateCustomSessionLevelTimeZoneTest.java b/hibernate-core/src/test/java/org/hibernate/test/timestamp/LocalDateCustomSessionLevelTimeZoneTest.java index e96b512f0f..050149e7e5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/timestamp/LocalDateCustomSessionLevelTimeZoneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/timestamp/LocalDateCustomSessionLevelTimeZoneTest.java @@ -13,9 +13,7 @@ import javax.persistence.Entity; import javax.persistence.Id; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.Dialect; import org.hibernate.dialect.MySQL5Dialect; -import org.hibernate.dialect.MySQL8Dialect; import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/type/AbstractJavaTimeTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/type/AbstractJavaTimeTypeTest.java index 93933bcaa2..2e5733d38c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/type/AbstractJavaTimeTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/type/AbstractJavaTimeTypeTest.java @@ -138,19 +138,21 @@ abstract class AbstractJavaTimeTypeTest extends BaseCoreFunctionalTestCase } ); inTransaction( session -> { session.doWork( connection -> { - final PreparedStatement statement = connection.prepareStatement( + try (PreparedStatement statement = connection.prepareStatement( "SELECT " + PROPERTY_COLUMN_NAME + " FROM " + ENTITY_NAME + " WHERE " + ID_COLUMN_NAME + " = ?" - ); - statement.setInt( 1, 1 ); - statement.execute(); - final ResultSet resultSet = statement.getResultSet(); - resultSet.next(); - Object nativeRead = getActualJdbcValue( resultSet, 1 ); - assertEquals( - "Values written by Hibernate ORM should match the original value (same day, hour, ...)", - getExpectedJdbcValueAfterHibernateWrite(), - nativeRead - ); + )) { + statement.setInt( 1, 1 ); + statement.execute(); + try (ResultSet resultSet = statement.getResultSet()) { + resultSet.next(); + Object nativeRead = getActualJdbcValue( resultSet, 1 ); + assertEquals( + "Values written by Hibernate ORM should match the original value (same day, hour, ...)", + getExpectedJdbcValueAfterHibernateWrite(), + nativeRead + ); + } + } } ); } ); } ); @@ -164,13 +166,14 @@ abstract class AbstractJavaTimeTypeTest extends BaseCoreFunctionalTestCase withDefaultTimeZone( () -> { inTransaction( session -> { session.doWork( connection -> { - final PreparedStatement statement = connection.prepareStatement( + try (PreparedStatement statement = connection.prepareStatement( "INSERT INTO " + ENTITY_NAME + " (" + ID_COLUMN_NAME + ", " + PROPERTY_COLUMN_NAME + ") " + " VALUES ( ? , ? )" - ); - statement.setInt( 1, 1 ); - setJdbcValueForNonHibernateWrite( statement, 2 ); - statement.execute(); + )) { + statement.setInt( 1, 1 ); + setJdbcValueForNonHibernateWrite( statement, 2 ); + statement.execute(); + } } ); } ); inTransaction( session -> { diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/PreparedStatementSpyConnectionProvider.java b/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/PreparedStatementSpyConnectionProvider.java index 69ee14569c..b4ac7872f3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/PreparedStatementSpyConnectionProvider.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/jdbc/PreparedStatementSpyConnectionProvider.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; import java.util.stream.Collectors; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; @@ -39,6 +41,9 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe .defaultAnswer( org.mockito.Answers.CALLS_REAL_METHODS ); private static final MockSettings VERIFIEABLE_MOCK_SETTINGS = Mockito.withSettings() .defaultAnswer( org.mockito.Answers.CALLS_REAL_METHODS ); + // We must keep around the mocked connections, otherwise they are garbage collected and trigger finalizers + // Since we use CALLS_REAL_METHODS this might close underlying IO resources which makes other objects unusable + private static final Queue MOCKS = new LinkedBlockingQueue<>(); private final Map preparedStatementMap = new LinkedHashMap<>(); @@ -75,6 +80,7 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe @Override public Connection getConnection() throws SQLException { Connection connection = instrumentConnection( actualConnection() ); + MOCKS.add( connection ); acquiredConnections.add( connection ); return connection; } @@ -83,7 +89,7 @@ public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDe public void closeConnection(Connection conn) throws SQLException { acquiredConnections.remove( conn ); releasedConnections.add( conn ); - super.closeConnection( conn ); + super.closeConnection( (Connection) MockUtil.getMockSettings( conn ).getSpiedInstance() ); } @Override diff --git a/hibernate-core/src/test/resources/org/hibernate/query/hhh12225/Vehicle.hbm.xml b/hibernate-core/src/test/resources/org/hibernate/query/hhh12225/Vehicle.hbm.xml index 0ba5e09cde..c026b5d57e 100644 --- a/hibernate-core/src/test/resources/org/hibernate/query/hhh12225/Vehicle.hbm.xml +++ b/hibernate-core/src/test/resources/org/hibernate/query/hhh12225/Vehicle.hbm.xml @@ -20,7 +20,7 @@ - + diff --git a/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/TestHelper.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/TestHelper.java index 2155f26477..81be696f60 100644 --- a/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/TestHelper.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/TestHelper.java @@ -76,7 +76,7 @@ public class TestHelper { final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .configure( "hibernate-config/hibernate.cfg.xml" ) .applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ) - .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) + .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapLobTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapLobTest.java index 3eb944598f..347b9dfc92 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapLobTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapLobTest.java @@ -16,6 +16,8 @@ import javax.persistence.Id; import javax.persistence.Lob; import org.hibernate.dialect.AbstractHANADialect; +import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.envers.Audited; @@ -37,6 +39,8 @@ import static org.junit.Assert.assertEquals; @SkipForDialect(Oracle8iDialect.class) @SkipForDialect(value = PostgreSQL81Dialect.class, jiraKey = "HHH-11477", comment = "@Lob field in HQL predicate fails with error about text = bigint") @SkipForDialect(value = AbstractHANADialect.class, comment = "HANA doesn't support comparing LOBs with the = operator") +@SkipForDialect(value = DB2Dialect.class, comment = "DB2 jdbc driver doesn't support setNString") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby jdbc driver doesn't support setNString") public class StringMapLobTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapNationalizedLobTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapNationalizedLobTest.java index 4c94ab6ac3..9eab2375b2 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapNationalizedLobTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/collection/StringMapNationalizedLobTest.java @@ -17,6 +17,8 @@ import javax.persistence.Lob; import org.hibernate.annotations.Nationalized; import org.hibernate.dialect.AbstractHANADialect; +import org.hibernate.dialect.DB2Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.SybaseDialect; @@ -40,6 +42,8 @@ import static org.junit.Assert.assertEquals; @SkipForDialect(value = PostgreSQL81Dialect.class, jiraKey = "HHH-11477", comment = "@Lob field in HQL predicate fails with error about text = bigint") @SkipForDialect(value = AbstractHANADialect.class, comment = "HANA doesn't support comparing LOBs with the = operator") @SkipForDialect(value = SybaseDialect.class, comment = "Sybase doesn't support comparing LOBs with the = operator") +@SkipForDialect(value = DB2Dialect.class, comment = "DB2 jdbc driver doesn't support setNString") +@SkipForDialect(value = DerbyDialect.class, comment = "Derby jdbc driver doesn't support setNString") public class StringMapNationalizedLobTest extends BaseEnversJPAFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/OrderSequenceGenerationTest.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/OrderSequenceGenerationTest.java index 8d2e7f62ce..da8fb81a37 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/OrderSequenceGenerationTest.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/tools/OrderSequenceGenerationTest.java @@ -17,6 +17,7 @@ import org.hibernate.dialect.Oracle8iDialect; import org.hibernate.envers.test.BaseEnversJPAFunctionalTestCase; import org.hibernate.envers.test.entities.StrTestEntity; +import org.hibernate.testing.BeforeClassOnce; import org.hibernate.testing.DialectChecks; import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.TestForIssue; @@ -45,7 +46,7 @@ public class OrderSequenceGenerationTest extends BaseEnversJPAFunctionalTestCase return new Class[] { StrTestEntity.class }; } - @Before + @Override public void buildEntityManagerFactory() throws Exception { createSchema = File.createTempFile( "create_schema", ".sql" ); dropSchema = File.createTempFile( "drop_schema", ".sql" ); @@ -58,7 +59,7 @@ public class OrderSequenceGenerationTest extends BaseEnversJPAFunctionalTestCase options.put( AvailableSettings.HBM2DDL_SCRIPTS_CREATE_TARGET, createSchema.toPath() ); options.put( AvailableSettings.HBM2DDL_SCRIPTS_DROP_TARGET, dropSchema.toPath() ); options.put( AvailableSettings.HBM2DDL_SCRIPTS_ACTION, "drop-and-create" ); - options.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop-and-create" ); + options.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); options.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); } diff --git a/hibernate-hikaricp/src/test/java/org/hibernate/test/util/PreparedStatementSpyConnectionProvider.java b/hibernate-hikaricp/src/test/java/org/hibernate/test/util/PreparedStatementSpyConnectionProvider.java index 4b72c265b1..7fdd38ef2c 100644 --- a/hibernate-hikaricp/src/test/java/org/hibernate/test/util/PreparedStatementSpyConnectionProvider.java +++ b/hibernate-hikaricp/src/test/java/org/hibernate/test/util/PreparedStatementSpyConnectionProvider.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Queue; +import java.util.concurrent.LinkedBlockingQueue; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; @@ -32,6 +34,9 @@ import org.mockito.internal.util.MockUtil; public class PreparedStatementSpyConnectionProvider extends ConnectionProviderDelegate { + // We must keep around the mocked connections, otherwise the are garbage collected and trigger finalizers + // Since we use CALLS_REAL_METHODS this might close underlying IO resources which make other objects unusable + private static final Queue MOCKS = new LinkedBlockingQueue<>(); private final Map preparedStatementMap = new LinkedHashMap<>(); private final List acquiredConnections = new ArrayList<>( ); @@ -47,6 +52,7 @@ public class PreparedStatementSpyConnectionProvider @Override public Connection getConnection() throws SQLException { Connection connection = spy( actualConnection() ); + MOCKS.add( connection ); acquiredConnections.add( connection ); return connection; } @@ -55,7 +61,7 @@ public class PreparedStatementSpyConnectionProvider public void closeConnection(Connection conn) throws SQLException { acquiredConnections.remove( conn ); releasedConnections.add( conn ); - super.closeConnection( conn ); + super.closeConnection( (Connection) MockUtil.getMockSettings( conn ).getSpiedInstance() ); } @Override diff --git a/hibernate-jcache/src/test/java/org/hibernate/jcache/test/RefreshUpdatedDataTest.java b/hibernate-jcache/src/test/java/org/hibernate/jcache/test/RefreshUpdatedDataTest.java index f0d43a0f89..5ea6db0adf 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/jcache/test/RefreshUpdatedDataTest.java +++ b/hibernate-jcache/src/test/java/org/hibernate/jcache/test/RefreshUpdatedDataTest.java @@ -21,6 +21,7 @@ import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.CockroachDB192Dialect; +import org.hibernate.dialect.DerbyDialect; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -58,7 +59,7 @@ public class RefreshUpdatedDataTest extends BaseUnitTestCase { serviceRegistry = ssrb .configure( "hibernate-config/hibernate.cfg.xml" ) - .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) + .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP ) .build(); final MetadataSources metadataSources = new MetadataSources( serviceRegistry ); @@ -87,6 +88,7 @@ public class RefreshUpdatedDataTest extends BaseUnitTestCase { @Test @SkipForDialect(value = CockroachDB192Dialect.class, comment = "does not support nested transactions") + @SkipForDialect(value = DerbyDialect.class, comment = "Derby does not support nested transactions") public void testUpdateAndFlushThenRefresh() { final String BEFORE = "before"; diff --git a/hibernate-jcache/src/test/java/org/hibernate/jcache/test/TestHelper.java b/hibernate-jcache/src/test/java/org/hibernate/jcache/test/TestHelper.java index bbcb0d329b..fa1711d855 100644 --- a/hibernate-jcache/src/test/java/org/hibernate/jcache/test/TestHelper.java +++ b/hibernate-jcache/src/test/java/org/hibernate/jcache/test/TestHelper.java @@ -113,7 +113,7 @@ public class TestHelper { final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .configure( "hibernate-config/hibernate.cfg.xml" ) .applySetting( AvailableSettings.GENERATE_STATISTICS, "true" ) - .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE ) + .applySetting( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP ) .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); if ( H2Dialect.class.equals( Dialect.getDialect().getClass() ) ) { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java index 6e7ea50ea0..f2f1b472f1 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/DialectChecks.java @@ -12,6 +12,7 @@ import org.hibernate.dialect.Dialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.SybaseDialect; +import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; /** * Container class for different implementation of the {@link DialectCheck} interface. @@ -291,4 +292,10 @@ abstract public class DialectChecks { ); } } + + public static class SupportsGlobalTemporaryTables implements DialectCheck { + public boolean isMatch(Dialect dialect) { + return dialect.getDefaultMultiTableBulkIdStrategy() instanceof GlobalTemporaryTableBulkIdStrategy; + } + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java index 541640390b..0c0886c683 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java @@ -33,7 +33,9 @@ import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.PostgreSQL81Dialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseASE15Dialect; +import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; +import org.hibernate.service.ServiceRegistry; import org.junit.Assert; @@ -155,6 +157,24 @@ public class TransactionUtil { } } + /** + * JDBC transaction function + * + * @param function result + */ + @FunctionalInterface + public interface JDBCTransactionFunction { + T accept(Connection connection) throws SQLException; + } + + /** + * JDBC transaction function without return value + */ + @FunctionalInterface + public interface JDBCTransactionVoidFunction { + void accept(Connection connection) throws SQLException; + } + /** * Execute function in a JPA transaction * @@ -692,4 +712,40 @@ public class TransactionUtil { public static void doInAutoCommit(String... statements) { doInAutoCommit( null, statements ); } + + public static void doWithJDBC(ServiceRegistry serviceRegistry, JDBCTransactionVoidFunction function) throws SQLException { + final JdbcConnectionAccess connectionAccess = serviceRegistry.getService( JdbcServices.class ) + .getBootstrapJdbcConnectionAccess(); + Connection connection = connectionAccess.obtainConnection(); + try { + function.accept( connection ); + } + finally { + if ( connection != null ) { + try { + connectionAccess.releaseConnection( connection ); + } + catch (SQLException ignore) { + } + } + } + } + + public static T doWithJDBC(ServiceRegistry serviceRegistry, JDBCTransactionFunction function) throws SQLException { + final JdbcConnectionAccess connectionAccess = serviceRegistry.getService( JdbcServices.class ) + .getBootstrapJdbcConnectionAccess(); + Connection connection = connectionAccess.obtainConnection(); + try { + return function.accept( connection ); + } + finally { + if ( connection != null ) { + try { + connectionAccess.releaseConnection( connection ); + } + catch (SQLException ignore) { + } + } + } + } }