Fix most tests to work on all DBs and fix a bunch of connection leaks

This commit is contained in:
Christian Beikov 2021-02-03 10:55:07 +01:00
parent 5d9f6936ff
commit d767d46d05
80 changed files with 628 additions and 185 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <<EOF | \$ORACLE_HOME/bin/sqlplus sys/Oracle18@localhost/XE as sysdba
alter database tempfile '/opt/oracle/oradata/XE/temp01.dbf' resize 400M;
alter database datafile '/opt/oracle/oradata/XE/system01.dbf' resize 1000M;
alter database datafile '/opt/oracle/oradata/XE/sysaux01.dbf' resize 600M;
alter database datafile '/opt/oracle/oradata/XE/undotbs01.dbf' resize 300M;
alter database add logfile group 4 '/opt/oracle/oradata/XE/redo04.log' size 500M reuse;
alter database add logfile group 5 '/opt/oracle/oradata/XE/redo05.log' size 500M reuse;
alter database add logfile group 6 '/opt/oracle/oradata/XE/redo06.log' size 500M reuse;
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system checkpoint;
alter database drop logfile group 1;
alter database drop logfile group 2;
alter database drop logfile group 3;
EOF\""
}
if [ -z ${1} ]; then

View File

@ -136,7 +136,7 @@ public class ListenerTest extends BaseEntityManagerFunctionalTestCase {
}
//tag::events-jpa-callbacks-example[]
@Entity
@Entity(name = "Person")
@EntityListeners( LastUpdateListener.class )
public static class Person {

View File

@ -25,6 +25,7 @@ import org.hibernate.CacheMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.dialect.CockroachDB192Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.Oracle8iDialect;
@ -1178,6 +1179,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_concat_function_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
//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[]

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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'
],
]
}

View File

@ -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 )
}

View File

@ -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

View File

@ -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

View File

@ -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
);
}

View File

@ -608,4 +608,9 @@ public class DerbyDialect extends DB2Dialect {
}
}, AfterUseAction.CLEAN, null);
}
@Override
public boolean supportsPartitionBy() {
return false;
}
}

View File

@ -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;

View File

@ -55,7 +55,7 @@ public abstract class AbstractMultiTableBulkIdStrategyImpl<TT extends IdTableInf
// build insert-select
// build id-subselect
final CT context = buildPreparationContext();
final CT context = buildPreparationContext();
initialize( metadata.getMetadataBuildingOptions(), sessionFactoryOptions );

View File

@ -15,6 +15,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;
@ -99,7 +100,8 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Entity
@Entity(name = "Order")
@Table(name = "orders")
private static class Order {
@Id
@GeneratedValue
@ -117,7 +119,7 @@ public class MergeTest extends BaseEntityManagerFunctionalTestCase {
}
}
@Entity
@Entity(name = "Item")
private static class Item {
@Id
@GeneratedValue

View File

@ -254,14 +254,14 @@ public class TreatKeywordTest extends BaseEntityManagerFunctionalTestCase {
em.close();
}
@Entity
@Entity(name = "TreatAnimal")
public static abstract class TreatAnimal {
@Id
@GeneratedValue
private Long id;
}
@Entity
@Entity(name = "Dog")
public static abstract class Dog extends TreatAnimal {
private boolean fast;
@ -274,14 +274,14 @@ public class TreatKeywordTest extends BaseEntityManagerFunctionalTestCase {
}
}
@Entity
@Entity(name = "Dachshund")
public static class Dachshund extends Dog {
public Dachshund() {
super( false );
}
}
@Entity
@Entity(name = "Greyhound")
public static class Greyhound extends Dog {
public Greyhound() {
super( true );

View File

@ -14,6 +14,7 @@ import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.hibernate.dialect.CockroachDB192Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.Oracle12cDialect;
import org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest;
import org.hibernate.jpa.test.metamodel.CreditCard;
@ -300,6 +301,7 @@ public class PredicateTest extends AbstractMetamodelSpecificTest {
@Test
@TestForIssue( jiraKey = "HHH-8901" )
@RequiresDialectFeature( DialectChecks.NotSupportsEmptyInListCheck.class )
@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't like `x in (null)`")
public void testEmptyInPredicate() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();

View File

@ -16,6 +16,7 @@ import javax.persistence.criteria.CriteriaQuery;
import org.hibernate.dialect.CockroachDB192Dialect;
import org.hibernate.dialect.PostgreSQL81Dialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.SkipForDialect;
@ -64,11 +65,11 @@ public class CriteriaLiteralWithSingleQuoteTest extends BaseEntityManagerFunctio
@Test
@SkipForDialects(
value = {
@SkipForDialect(value = SQLServerDialect.class, comment = "SQLServer does not support literals in group by statement"),
@SkipForDialect(value = PostgreSQL81Dialect.class, comment = "PostgreSQL does not support literals in group by statement"),
@SkipForDialect( value = CockroachDB192Dialect.class, comment = "CockroachDB does not support literals in group by statement")
}
)
@SkipForDialect(value = PostgreSQL81Dialect.class, comment = "PostgreSQL does not support literals in group by statement")
public void testLiteralProjectionAndGroupBy() throws Exception {
doInJPA(
this::entityManagerFactory,

View File

@ -17,6 +17,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.PostgreSQL95Dialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.jpa.test.metadata.Person_;
@ -32,6 +33,7 @@ import static org.junit.Assert.assertTrue;
@TestForIssue(jiraKey = "HHH-12230")
@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 GroupBySelectCaseTest extends BaseEntityManagerFunctionalTestCase {
@Override

View File

@ -17,9 +17,12 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
import org.hibernate.query.criteria.LiteralHandlingMode;
import org.hibernate.testing.SkipForDialect;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
@ -101,6 +104,8 @@ public class SelectCaseLiteralHandlingBindTest extends BaseEntityManagerFunction
}
@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 whereCaseExpression() {
doInJPA( this::entityManagerFactory, entityManager -> {

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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 );

View File

@ -165,6 +165,11 @@ public class FlushAndTransactionTest extends BaseEntityManagerFunctionalTestCase
catch ( IllegalStateException e ) {
//success
}
finally {
if ( em.getTransaction().isActive() ) {
em.getTransaction().rollback();
}
}
}
@Test

View File

@ -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();
}

View File

@ -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();

View File

@ -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();

View File

@ -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(

View File

@ -161,7 +161,7 @@ public class JaccIntegratorTest extends BaseEntityManagerFunctionalTestCase {
}
}
@Entity
@Entity(name = "Person")
public static class Person {
@Id

View File

@ -33,6 +33,7 @@ public class EmbeddableWithOneToMany_HHH_11302_xml_Test extends
};
}
@Override
public void buildEntityManagerFactory() {
try {
super.buildEntityManagerFactory();

View File

@ -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();
}
}

View File

@ -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 );

View File

@ -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

View File

@ -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

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -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")

View File

@ -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,

View File

@ -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();

View File

@ -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 {

View File

@ -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;

View File

@ -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 );

View File

@ -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();

View File

@ -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();

View File

@ -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) ");

View File

@ -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();

View File

@ -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,

View File

@ -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,

View File

@ -78,6 +78,7 @@ public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase
for ( String createSequenceStatement : createSequenceStatements ) {
statement.execute( createSequenceStatement );
}
connection.commit();
}
catch (SQLException e) {
fail( e.getMessage() );

View File

@ -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<Employee> 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 );

View File

@ -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<Employee> 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 );

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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() {

View File

@ -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;

View File

@ -138,19 +138,21 @@ abstract class AbstractJavaTimeTypeTest<T, E> 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<T, E> 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 -> {

View File

@ -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<Object> MOCKS = new LinkedBlockingQueue<>();
private final Map<PreparedStatement, String> 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

View File

@ -20,7 +20,7 @@
<property name="dirty" type="boolean" />
<property name="decodeAttempts" type="java.lang.Integer" column="decode_attempts"/>
<property name="year" type="java.lang.Integer" column="year" />
<property name="year" type="java.lang.Integer" column="year_value" />
<property name="msrp" type="java.lang.Double" column="msrp_value" />
<property name="residualValue" type="java.lang.Double" column="residual_value" />
<property name="invoicePrice" type="java.lang.Double" column="invoice_price" />

View File

@ -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() ) ) {

View File

@ -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() {

View File

@ -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() {

View File

@ -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" );
}

View File

@ -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<Object> MOCKS = new LinkedBlockingQueue<>();
private final Map<PreparedStatement, String> preparedStatementMap = new LinkedHashMap<>();
private final List<Connection> 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

View File

@ -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";

View File

@ -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() ) ) {

View File

@ -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;
}
}
}

View File

@ -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 <T> function result
*/
@FunctionalInterface
public interface JDBCTransactionFunction<T> {
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> T doWithJDBC(ServiceRegistry serviceRegistry, JDBCTransactionFunction<T> 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) {
}
}
}
}
}