diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java index a6ace62004..2b8af3476e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java @@ -13,6 +13,7 @@ import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Enumeration; +import java.util.Iterator; import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentLinkedQueue; @@ -302,6 +303,10 @@ public class DriverManagerConnectionProviderImpl } } + protected void validateConnections(ConnectionValidator validator) { + state.validateConnections( validator ); + } + // destroy the pool ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @Override @@ -655,6 +660,42 @@ public class DriverManagerConnectionProviderImpl statelock.readLock().unlock(); } } + + public void validateConnections(ConnectionValidator validator) { + if ( !active ) { + return; + } + statelock.writeLock().lock(); + try { + RuntimeException ex = null; + for ( Iterator iterator = pool.allConnections.iterator(); iterator.hasNext(); ) { + final Connection connection = iterator.next(); + SQLException e = null; + boolean isValid = false; + try { + isValid = validator.isValid( connection ); + } + catch (SQLException sqlException) { + e = sqlException; + } + if ( !isValid ) { + pool.closeConnection( connection, e ); + if ( ex == null ) { + ex = new RuntimeException( e ); + } + else if ( e != null ) { + ex.addSuppressed( e ); + } + } + } + if ( ex != null ) { + throw ex; + } + } + finally { + statelock.writeLock().unlock(); + } + } } private static class ValidationThreadFactory implements ThreadFactory { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAggregateTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAggregateTest.java index d1d7ecc5ba..10c6c3d615 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAggregateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAggregateTest.java @@ -13,7 +13,6 @@ import org.hibernate.boot.spi.AdditionalMappingContributions; import org.hibernate.boot.spi.AdditionalMappingContributor; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.OracleArrayJdbcType; import org.hibernate.dialect.SpannerDialect; import org.hibernate.engine.jdbc.Size; @@ -26,16 +25,15 @@ import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.spi.TypeConfiguration; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.domain.gambit.EntityOfBasics; import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -52,12 +50,10 @@ import static org.junit.jupiter.api.Assertions.assertNull; javaServices = @BootstrapServiceRegistry.JavaService( role = AdditionalMappingContributor.class, impl = ArrayAggregateTest.UdtContributor.class - ) + ), + // Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete + integrators = SharedDriverManagerTypeCacheClearingIntegrator.class ) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) @DomainModel(standardModels = StandardDomainModel.GAMBIT) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsStructuralArrays.class) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAppendTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAppendTest.java index 43d5672133..43d1d23ba6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAppendTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayAppendTest.java @@ -7,28 +7,24 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.testing.orm.domain.gambit.EntityOfBasics; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.Expression; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayAppendTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConcatTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConcatTest.java index 18005a531a..2f02cf5289 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConcatTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConcatTest.java @@ -6,22 +6,19 @@ */ package org.hibernate.orm.test.function.array; -import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,10 +35,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayConcatTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConstructorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConstructorTest.java index 2e85a8e1ca..45d585e339 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConstructorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayConstructorTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayConstructorTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsArrayTest.java index c28f3af869..94280e67ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsArrayTest.java @@ -7,29 +7,24 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.HSQLDialect; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; -import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.Expression; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -39,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayContainsArrayTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsTest.java index fca998aba3..179f16867d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayContainsTest.java @@ -7,27 +7,24 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import jakarta.persistence.Tuple; -import jakarta.persistence.criteria.Expression; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -37,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayContainsTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayFillTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayFillTest.java index 19e2b3f3ec..2b8f097e02 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayFillTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayFillTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,10 +35,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayFillTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayGetTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayGetTest.java index 12ad798be0..eb292df7e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayGetTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayGetTest.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.function.array; -import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,10 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayGetTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayLengthTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayLengthTest.java index a7f32b6cf3..fd7fd34374 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayLengthTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayLengthTest.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.function.array; -import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,10 +33,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayLengthTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayOverlapsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayOverlapsTest.java index 75c8a77aab..75fa2fbf9d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayOverlapsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayOverlapsTest.java @@ -7,23 +7,19 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.HSQLDialect; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; -import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayOverlapsTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java index 6dbb908a31..26a8a97645 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java @@ -7,21 +7,19 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,10 +34,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayPositionTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionsTest.java index 02bfa123d5..3e387cf23b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionsTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayPositionsTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPrependTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPrependTest.java index 2fcc6b93af..7eb6c7822f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPrependTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPrependTest.java @@ -7,21 +7,19 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayPrependTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveIndexTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveIndexTest.java index 6a4d073994..c1f35580b8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveIndexTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveIndexTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayRemoveIndexTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveTest.java index 9725983624..cfbc037b82 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayRemoveTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayRemoveTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayReplaceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayReplaceTest.java index f72dc04eac..1214de3dbb 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayReplaceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayReplaceTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,10 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayReplaceTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySetTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySetTest.java index 9b0242e9bb..45a620cfb6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySetTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySetTest.java @@ -9,18 +9,17 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,10 +35,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArraySetTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySliceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySliceTest.java index e14bfa2219..aa1c0594ad 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySliceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArraySliceTest.java @@ -6,22 +6,20 @@ */ package org.hibernate.orm.test.function.array; -import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.CockroachDialect; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -39,10 +37,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) @SkipForDialect(dialectClass = CockroachDialect.class, reason = "See https://github.com/cockroachdb/cockroach/issues/32551") public class ArraySliceTest { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayToStringTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayToStringTest.java index f26442e850..86f5273a69 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayToStringTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayToStringTest.java @@ -8,18 +8,17 @@ package org.hibernate.orm.test.function.array; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,13 +32,11 @@ import static org.junit.jupiter.api.Assertions.assertNull; /** * @author Christian Beikov */ -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature(feature = DialectFeatureChecks.SupportsStructuralArrays.class) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayToStringTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayTrimTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayTrimTest.java index ae98161af8..4775142424 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayTrimTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayTrimTest.java @@ -10,20 +10,19 @@ import java.sql.SQLException; import java.util.Collection; import java.util.List; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.CockroachDialect; import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DialectFeatureChecks; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.RequiresDialectFeature; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -43,10 +42,8 @@ import static org.junit.jupiter.api.Assertions.fail; @DomainModel(annotatedClasses = EntityWithArrays.class) @SessionFactory @RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class ArrayTrimTest { @BeforeEach diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BasicCollectionMappingTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BasicCollectionMappingTests.java index 4444950e2c..99c6ba91e3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BasicCollectionMappingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/BasicCollectionMappingTests.java @@ -12,19 +12,18 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; -import org.hibernate.cfg.AvailableSettings; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; import org.hibernate.metamodel.spi.MappingMetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.jdbc.SQLStatementInspector; +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.Jira; -import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -41,10 +40,8 @@ import static org.hamcrest.Matchers.equalTo; */ @DomainModel(annotatedClasses = BasicCollectionMappingTests.EntityOfCollections.class) @SessionFactory( useCollectingStatementInspector = true ) -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class BasicCollectionMappingTests { @Test diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleNestedTableTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleNestedTableTest.java index b47e49ff74..2efc173902 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleNestedTableTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleNestedTableTest.java @@ -1,38 +1,36 @@ package org.hibernate.orm.test.type; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.hibernate.annotations.Array; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.dialect.OracleDialect; +import org.hibernate.type.SqlTypes; + +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; -import org.hibernate.annotations.Array; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.OracleDialect; -import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.RequiresDialect; -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.SessionFactory; -import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; - -import org.hibernate.type.SqlTypes; -import org.junit.jupiter.api.Test; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @SessionFactory -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) @DomainModel(annotatedClasses = {OracleNestedTableTest.Container.class}) @RequiresDialect(OracleDialect.class) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class OracleNestedTableTest { @Test public void test(SessionFactoryScope scope) { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleSqlArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleSqlArrayTest.java index 1ce9ac4ca7..d261e8cf96 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleSqlArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/OracleSqlArrayTest.java @@ -1,39 +1,37 @@ package org.hibernate.orm.test.type; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import org.hibernate.annotations.Array; -import org.hibernate.annotations.JdbcTypeCode; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.dialect.OracleDialect; -import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.RequiresDialect; -import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.SessionFactory; -import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.testing.orm.junit.Setting; - -import org.hibernate.type.SqlTypes; -import org.junit.jupiter.api.Test; - import java.math.BigInteger; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import org.hibernate.annotations.Array; +import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.dialect.OracleDialect; +import org.hibernate.type.SqlTypes; + +import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator; +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @SessionFactory -// Make sure this stuff runs on a dedicated connection pool, -// otherwise we might run into ORA-21700: object does not exist or is marked for delete -// because the JDBC connection or database session caches something that should have been invalidated -@ServiceRegistry(settings = @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = "")) @DomainModel(annotatedClasses = {OracleSqlArrayTest.Container.class}) @RequiresDialect(OracleDialect.class) +// Clear the type cache, otherwise we might run into ORA-21700: object does not exist or is marked for delete +@BootstrapServiceRegistry(integrators = SharedDriverManagerTypeCacheClearingIntegrator.class) public class OracleSqlArrayTest { @Test public void test(SessionFactoryScope scope) { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerConnectionProviderImpl.java b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerConnectionProviderImpl.java index 28e105f267..3b37aaf12f 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerConnectionProviderImpl.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerConnectionProviderImpl.java @@ -73,6 +73,22 @@ public class SharedDriverManagerConnectionProviderImpl extends DriverManagerConn validateConnectionsReturned(); } + public void clearTypeCache() { + if ( "oracle.jdbc.OracleDriver".equals( config.driverClassName ) ) { + validateConnections( c -> { + try { + final Class oracleConnection = Class.forName( "oracle.jdbc.OracleConnection" ); + final Object connection = c.unwrap( oracleConnection ); + oracleConnection.getMethod( "removeAllDescriptor").invoke( connection ); + return true; + } + catch (Exception e) { + throw new RuntimeException( e ); + } + } ); + } + } + public void onDefaultTimeZoneChange() { if ( "org.h2.Driver".equals( config.driverClassName ) || "org.hsqldb.jdbc.JDBCDriver".equals( config.driverClassName ) ) { // Clear the connection pool to avoid issues with drivers that initialize the session TZ to the system TZ diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerTypeCacheClearingIntegrator.java b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerTypeCacheClearingIntegrator.java new file mode 100644 index 0000000000..37dfa4d1c7 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/jdbc/SharedDriverManagerTypeCacheClearingIntegrator.java @@ -0,0 +1,26 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.testing.jdbc; + +import org.hibernate.boot.Metadata; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.integrator.spi.Integrator; +import org.hibernate.service.spi.SessionFactoryServiceRegistry; + +public class SharedDriverManagerTypeCacheClearingIntegrator implements Integrator { + @Override + public void integrate( + Metadata metadata, + SessionFactoryImplementor sessionFactory, + SessionFactoryServiceRegistry serviceRegistry) { + SharedDriverManagerConnectionProviderImpl.getInstance().clearTypeCache(); + } + + @Override + public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) { + } +}