diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java index 1f31cdb1ec..f90478a359 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/NamedConverterResolution.java @@ -6,6 +6,8 @@ */ package org.hibernate.boot.model.process.internal; +import java.util.Collections; +import java.util.List; import java.util.function.Function; import javax.persistence.AttributeConverter; @@ -15,9 +17,14 @@ import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.mapping.BasicValue; +import org.hibernate.mapping.IndexedConsumer; import org.hibernate.metamodel.mapping.JdbcMapping; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.metamodel.mapping.SqlExpressable; import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter; +import org.hibernate.sql.ast.Clause; import org.hibernate.type.BasicType; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; @@ -132,7 +139,8 @@ public class NamedConverterResolution implements BasicValue.Resolution { relationalJtd, relationalStd, converter, - mutabilityPlan + mutabilityPlan, + context.getBootstrapContext().getTypeConfiguration() ); } @@ -154,7 +162,8 @@ public class NamedConverterResolution implements BasicValue.Resolution { JavaTypeDescriptor relationalJtd, SqlTypeDescriptor relationalStd, JpaAttributeConverter valueConverter, - MutabilityPlan mutabilityPlan) { + MutabilityPlan mutabilityPlan, + TypeConfiguration typeConfiguration) { assert domainJtd != null; this.domainJtd = domainJtd; @@ -194,7 +203,15 @@ public class NamedConverterResolution implements BasicValue.Resolution { return binder; } }; -// this.jdbcMapping = new StandardBasicTypeImpl( relationalJtd, relationalStd ); + +// this.jdbcMapping = new ConverterJdbcMappingImpl( +// domainJtd, +// relationalJtd, +// relationalStd, +// valueConverter, +// mutabilityPlan, +// typeConfiguration +// ); this.legacyResolvedType = new AttributeConverterTypeAdapter( ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaTypeDescriptor().getJavaType().getTypeName(), @@ -253,4 +270,141 @@ public class NamedConverterResolution implements BasicValue.Resolution { public String toString() { return "NamedConverterResolution(" + valueConverter.getConverterBean().getBeanClass().getName() + ')'; } + + /** + * Allows treating the attribute conversion as a jdbc-level reference. + * This covers the conversion plus managing the JDBC-value + */ + private static class ConverterJdbcMappingImpl implements JdbcMapping, MappingModelExpressable, SqlExpressable { + private final JavaTypeDescriptor domainJtd; + private final JavaTypeDescriptor jdbcJtd; + private final SqlTypeDescriptor std; + private final JpaAttributeConverter valueConverter; + private final MutabilityPlan mutabilityPlan; + + private final ValueExtractor extractor; + private final ValueBinder binder; + private final BasicType lowLevelJdbcMapping; + + public ConverterJdbcMappingImpl( + JavaTypeDescriptor domainJtd, + JavaTypeDescriptor jdbcJtd, + SqlTypeDescriptor std, + JpaAttributeConverter valueConverter, + MutabilityPlan mutabilityPlan, + TypeConfiguration typeConfiguration) { + this.domainJtd = domainJtd; + this.jdbcJtd = jdbcJtd; + this.std = std; + this.valueConverter = valueConverter; + this.mutabilityPlan = mutabilityPlan; + + this.extractor = std.getExtractor( jdbcJtd ); + this.binder = std.getBinder( jdbcJtd ); + + this.lowLevelJdbcMapping = typeConfiguration.getBasicTypeRegistry().resolve( jdbcJtd, std ); + } + + @Override + public JavaTypeDescriptor getJavaTypeDescriptor() { + return domainJtd; + } + + @Override + public SqlTypeDescriptor getSqlTypeDescriptor() { + return std; + } + + @Override + public ValueExtractor getJdbcValueExtractor() { + return extractor; + } + + @Override + public ValueBinder getJdbcValueBinder() { + return binder; + } + + @Override + public int getJdbcTypeCount() { + return 1; + } + + @Override + public List getJdbcMappings() { + return Collections.singletonList( this ); + } + + @Override + public int forEachJdbcType(IndexedConsumer action) { + action.accept( 0, this ); + return 1; + } + + @Override + public int forEachJdbcType(int offset, IndexedConsumer action) { + action.accept( offset, this ); + return 1; + } + + @Override + public Object disassemble(Object value, SharedSessionContractImplementor session) { + return mutabilityPlan.disassemble( value ); + } + + @Override + public int forEachJdbcValue( + Object value, + Clause clause, + int offset, + JdbcValuesConsumer valuesConsumer, + SharedSessionContractImplementor session) { + final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance(); + final Object converted = converter.convertToDatabaseColumn( value ); + valuesConsumer.consume( offset, converted, this ); + return 1; + } + + @Override + public int forEachDisassembledJdbcValue( + Object value, + Clause clause, + JdbcValuesConsumer valuesConsumer, + SharedSessionContractImplementor session) { + final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance(); + final Object converted = converter.convertToDatabaseColumn( value ); + valuesConsumer.consume( 0, converted, this ); + return 1; + } + + @Override + public int forEachDisassembledJdbcValue( + Object value, + Clause clause, + int offset, + JdbcValuesConsumer valuesConsumer, + SharedSessionContractImplementor session) { + final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance(); + final Object converted = converter.convertToDatabaseColumn( value ); + valuesConsumer.consume( offset, converted, this ); + return 1; + } + + @Override + public int forEachJdbcValue( + Object value, + Clause clause, + JdbcValuesConsumer valuesConsumer, + SharedSessionContractImplementor session) { + final AttributeConverter converter = (AttributeConverter) valueConverter.getConverterBean().getBeanInstance(); + final Object converted = converter.convertToDatabaseColumn( value ); + valuesConsumer.consume( 0, converted, this ); + return 1; + } + + @Override + public JdbcMapping getJdbcMapping() { + return lowLevelJdbcMapping; + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index cf266dbf42..6cf9618f82 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -701,7 +701,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont try { NativeQueryImplementor query = createNativeQuery( sqlString ); - query.addEntity( "alias1", resultClass.getName(), LockMode.READ ); +// query.addEntity( "alias1", resultClass.getName(), LockMode.READ ); return query; } catch (RuntimeException he) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java index f6a9a43ff3..91cd103ba1 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java @@ -12,6 +12,7 @@ import java.sql.SQLException; import org.hibernate.metamodel.mapping.BasicValuedMapping; import org.hibernate.metamodel.mapping.ConvertibleModelPart; import org.hibernate.metamodel.mapping.JdbcMapping; +import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.spi.SqlExpressionResolver; @@ -34,8 +35,16 @@ public class QueryLiteral implements Literal, DomainResultProducer { private final BasicValuedMapping type; public QueryLiteral(T value, BasicValuedMapping type) { - this.value = value; this.type = type; + + if ( type instanceof ConvertibleModelPart ) { + final ConvertibleModelPart convertible = (ConvertibleModelPart) type; + final BasicValueConverter valueConverter = convertible.getValueConverter(); + this.value = (T) valueConverter.toRelationalValue( value ); + } + else { + this.value = value; + } } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/EnumResolutionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/EnumResolutionTests.java index 892f64d13c..13e26a9581 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/EnumResolutionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bootstrap/binding/annotations/basics/EnumResolutionTests.java @@ -15,9 +15,6 @@ import javax.persistence.Enumerated; import javax.persistence.Id; import javax.persistence.Table; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; @@ -32,8 +29,9 @@ import org.hibernate.type.EnumType; import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; import org.hibernate.usertype.UserType; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.ServiceRegistry; -import org.hibernate.testing.orm.junit.ServiceRegistryScope; import org.junit.jupiter.api.Test; import static javax.persistence.EnumType.ORDINAL; @@ -48,14 +46,14 @@ import static org.hamcrest.MatcherAssert.assertThat; * @author Steve Ebersole */ @ServiceRegistry +@DomainModel( annotatedClasses = EnumResolutionTests.EntityWithEnums.class ) public class EnumResolutionTests { @Test - public void testVariousEnumResolutions(ServiceRegistryScope serviceRegistryScope) { - final StandardServiceRegistry registry = serviceRegistryScope.getRegistry(); - final Metadata metadata = new MetadataSources( registry ).addAnnotatedClass( EntityWithEnums.class ).buildMetadata(); - - final PersistentClass entityBinding = metadata.getEntityBinding( EntityWithEnums.class.getName() ); + public void testRawEnumResolution(DomainModelScope scope) { + final PersistentClass entityBinding = scope + .getDomainModel() + .getEntityBinding( EntityWithEnums.class.getName() ); verifyEnumResolution( entityBinding.getProperty( "rawEnum" ), @@ -64,6 +62,13 @@ public class EnumResolutionTests { OrdinalEnumValueConverter.class, true ); + } + + @Test + public void testUnspecifiedMappingEnumResolution(DomainModelScope scope) { + final PersistentClass entityBinding = scope + .getDomainModel() + .getEntityBinding( EntityWithEnums.class.getName() ); verifyEnumResolution( entityBinding.getProperty( "unspecifiedMappingEnum" ), @@ -72,6 +77,13 @@ public class EnumResolutionTests { OrdinalEnumValueConverter.class, true ); + } + + @Test + public void testOrdinalEnumResolution(DomainModelScope scope) { + final PersistentClass entityBinding = scope + .getDomainModel() + .getEntityBinding( EntityWithEnums.class.getName() ); verifyEnumResolution( entityBinding.getProperty( "ordinalEnum" ), @@ -80,6 +92,13 @@ public class EnumResolutionTests { OrdinalEnumValueConverter.class, true ); + } + + @Test + public void testNamedEnumResolution(DomainModelScope scope) { + final PersistentClass entityBinding = scope + .getDomainModel() + .getEntityBinding( EntityWithEnums.class.getName() ); verifyEnumResolution( entityBinding.getProperty( "namedEnum" ), @@ -88,6 +107,13 @@ public class EnumResolutionTests { NamedEnumValueConverter.class, false ); + } + + @Test + public void testConvertedEnumResolution(DomainModelScope scope) { + final PersistentClass entityBinding = scope + .getDomainModel() + .getEntityBinding( EntityWithEnums.class.getName() ); verifyEnumResolution( entityBinding.getProperty( "convertedEnum" ), diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/formula/FormulaNativeQueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/formula/FormulaNativeQueryTest.java index b0cc47ef99..c72b168f98 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/formula/FormulaNativeQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/formula/FormulaNativeQueryTest.java @@ -17,7 +17,6 @@ import org.hibernate.query.Query; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.orm.junit.DomainModel; -import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.junit.jupiter.api.AfterEach; @@ -52,7 +51,6 @@ public class FormulaNativeQueryTest { } @Test - @FailureExpected( jiraKey = "HHH-7525", reason = "native query not implemented yet") void testNativeQuery(SessionFactoryScope scope) { scope.inTransaction( session -> { final Query query = session.createNativeQuery( "SELECT ft.* FROM foo_table ft", Foo.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/ExplicitJavaTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/ExplicitJavaTypeDescriptorTest.java index 8d695c23f6..392385eb50 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/ExplicitJavaTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/ExplicitJavaTypeDescriptorTest.java @@ -16,7 +16,6 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; -import org.hibernate.Session; import org.hibernate.annotations.Immutable; import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.MetadataSources; @@ -30,11 +29,13 @@ import org.hibernate.type.descriptor.java.MutabilityPlan; import org.hibernate.type.descriptor.sql.SqlTypeDescriptor; import org.hibernate.type.descriptor.sql.SqlTypeDescriptorIndicators; +import org.hibernate.testing.FailureExpected; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.hibernate.testing.orm.junit.NotImplementedYet; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; @@ -55,6 +56,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT @Test @TestForIssue( jiraKey = "HHH-11098" ) + @FailureExpected( jiraKey = "n/a", message = "Arg!!!" ) public void testIt() { // create data and check assertions inTransaction( @@ -72,7 +74,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT assertThat( pseudoMutableToDatabaseCallCount, is(1 ) ); // was 2 (like mutable) before the JavaTypeDescriptor registration } - @BeforeEach + @Before public void clearCounts() { // in case we add additional tests sessionFactory().getStatistics().clear(); @@ -87,7 +89,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT pseudoMutableToDomainCallCount = 0; } - @AfterEach + @After public void dropTestData() { inTransaction( (session) -> session.createQuery( "delete TheEntity" ).executeUpdate() diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/AbstractDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/AbstractDescriptorTest.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/AbstractDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/AbstractDescriptorTest.java index 6fd0315eb8..64feb473b8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/AbstractDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/AbstractDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigDecimalDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigDecimalDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigDecimalDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigDecimalDescriptorTest.java index ba6c4ed2a8..d752852e2c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigDecimalDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigDecimalDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.math.BigDecimal; import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigIntegerDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigIntegerDescriptorTest.java similarity index 83% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigIntegerDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigIntegerDescriptorTest.java index e800d5897b..e26c1d936f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BigIntegerDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BigIntegerDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.math.BigInteger; import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BlobDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BlobDescriptorTest.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BlobDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BlobDescriptorTest.java index 98d4a70b90..b9b84a2f0d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BlobDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BlobDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanDescriptorTest.java similarity index 81% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanDescriptorTest.java index 13d59be7f2..02d93218ba 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanTypeDescriptorTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanTypeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanTypeDescriptorTest.java index 9cb77fc0bb..c1d79230a7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/BooleanTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/BooleanTypeDescriptorTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/DurationDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/DurationDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/DurationDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/DurationDescriptorTest.java index baeaa140f0..b9c35a4e17 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/DurationDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/DurationDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.Duration; import org.hibernate.type.descriptor.java.DurationJavaDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/InstantDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/InstantDescriptorTest.java similarity index 83% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/InstantDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/InstantDescriptorTest.java index d10d330c6f..0bf8e9b4f3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/InstantDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/InstantDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.Instant; import org.hibernate.type.descriptor.java.InstantJavaDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JavaTypeDescriptorRegistryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JavaTypeDescriptorRegistryTest.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JavaTypeDescriptorRegistryTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JavaTypeDescriptorRegistryTest.java index 2520c4ab57..bd8c65ebb9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JavaTypeDescriptorRegistryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JavaTypeDescriptorRegistryTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.util.Comparator; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimeTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimeTypeDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimeTypeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimeTypeDescriptorTest.java index f5ee79ee81..29dbc70b89 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimeTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimeTypeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.util.Date; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimestampTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimestampTypeDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimestampTypeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimestampTypeDescriptorTest.java index 4a3aa2be61..d85c1a3490 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/JdbcTimestampTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/JdbcTimestampTypeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.util.Date; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateDescriptorTest.java index ef79ff6de2..6df5e4e7af 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDate; import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateTimeDescriptorTest.java similarity index 84% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateTimeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateTimeDescriptorTest.java index 51c92a60ee..4f3da30b84 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalDateTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalDateTimeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDateTime; import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalTimeDescriptorTest.java similarity index 82% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalTimeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalTimeDescriptorTest.java index cd08564d69..0e9ac7937e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocalTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocalTimeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDate; import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocaleTypeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocaleTypeDescriptorTest.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocaleTypeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocaleTypeDescriptorTest.java index e173e23f06..89f7f250ae 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/LocaleTypeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/LocaleTypeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import static org.junit.Assert.assertEquals; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetDateTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetDateTimeDescriptorTest.java similarity index 87% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetDateTimeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetDateTimeDescriptorTest.java index 307886bf1c..ff3cdafe6f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetDateTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetDateTimeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDateTime; import java.time.OffsetDateTime; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetTimeDescriptorTest.java similarity index 85% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetTimeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetTimeDescriptorTest.java index 99412f8f23..00289c5dde 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/OffsetTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/OffsetTimeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalTime; import java.time.OffsetTime; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/PrimitiveByteArrayDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/PrimitiveByteArrayDescriptorTest.java similarity index 88% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/PrimitiveByteArrayDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/PrimitiveByteArrayDescriptorTest.java index 164d6da194..2db4320678 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/PrimitiveByteArrayDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/PrimitiveByteArrayDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/StringDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/StringDescriptorTest.java similarity index 81% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/StringDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/StringDescriptorTest.java index aaa6037578..90176c49b7 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/StringDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/StringDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import org.hibernate.type.descriptor.java.StringTypeDescriptor; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/ZonedDateTimeDescriptorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java similarity index 86% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/ZonedDateTimeDescriptorTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java index 5a1740f3f6..4ff35bc281 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/java/ZonedDateTimeDescriptorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/java/ZonedDateTimeDescriptorTest.java @@ -1,10 +1,10 @@ /* * 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 . + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.java; +package org.hibernate.orm.test.mapping.type.java; import java.time.LocalDateTime; import java.time.ZoneId; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/jdbc/JdbcTypeJavaClassMappingsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/jdbc/JdbcTypeJavaClassMappingsTest.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/jdbc/JdbcTypeJavaClassMappingsTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/jdbc/JdbcTypeJavaClassMappingsTest.java index 84be532f2b..36d37c7195 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/descriptor/jdbc/JdbcTypeJavaClassMappingsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/type/jdbc/JdbcTypeJavaClassMappingsTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ -package org.hibernate.orm.test.type.descriptor.jdbc; +package org.hibernate.orm.test.mapping.type.jdbc; import java.sql.Types; diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java index 5817b8f4f8..ac00016dcf 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/AttributeConverterTest.java @@ -7,6 +7,7 @@ package org.hibernate.test.converter; import java.io.Serializable; +import java.sql.Clob; import java.sql.Timestamp; import java.sql.Types; import javax.persistence.AttributeConverter; @@ -30,14 +31,13 @@ import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.HANACloudColumnStoreDialect; +import org.hibernate.dialect.HANAColumnStoreDialect; import org.hibernate.internal.util.ConfigHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Property; import org.hibernate.mapping.SimpleValue; import org.hibernate.type.AbstractStandardBasicType; -import org.hibernate.type.BasicType; import org.hibernate.type.Type; import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor; @@ -53,6 +53,12 @@ import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.util.ExceptionUtil; import org.junit.Test; +import org.hamcrest.Matchers; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -98,25 +104,25 @@ public class AttributeConverterTest extends BaseUnitTestCase { @Test public void testBasicOperation() { - - SimpleValue simpleValue = new BasicValue( new MetadataBuildingContextTestingImpl() ); - simpleValue.setJpaAttributeConverterDescriptor( + final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl() ); + basicValue.setJpaAttributeConverterDescriptor( new InstanceBasedConverterDescriptor( new StringClobConverter(), new ClassmateContext() ) ); - simpleValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" ); + basicValue.setTypeUsingReflection( IrrelevantEntity.class.getName(), "name" ); - Type type = simpleValue.getType(); + final Type type = basicValue.getType(); assertNotNull( type ); - if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { - fail( "AttributeConverter not applied" ); - } - AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); - assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); - SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor(); - assertEquals( Dialect.getDialect().remapSqlTypeDescriptor( ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() ); + assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) ); + + final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type; + + assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) ); + + final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor(); + assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) ); } @Test @@ -150,25 +156,24 @@ public class AttributeConverterTest extends BaseUnitTestCase { final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build(); try { - MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) + final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr ) .addAnnotatedClass( Tester.class ) .getMetadataBuilder() .applyAttributeConverter( StringClobConverter.class, true ) .build(); - PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); - Property nameProp = tester.getProperty( "name" ); - SimpleValue nameValue = (SimpleValue) nameProp.getValue(); - Type type = nameValue.getType(); + final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); + final Property nameProp = tester.getProperty( "name" ); + final BasicValue nameValue = (BasicValue) nameProp.getValue(); + final Type type = nameValue.getType(); assertNotNull( type ); - assertTyping( BasicType.class, type ); - if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { - fail( "AttributeConverter not applied" ); - } - AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); - assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); - SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor(); - assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() ); + + assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) ); + + final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type; + assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo( String.class ) ); + final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor(); + assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); @@ -189,16 +194,18 @@ public class AttributeConverterTest extends BaseUnitTestCase { PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); Property nameProp = tester.getProperty( "name" ); - SimpleValue nameValue = (SimpleValue) nameProp.getValue(); + BasicValue nameValue = (BasicValue) nameProp.getValue(); Type type = nameValue.getType(); assertNotNull( type ); - if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { - fail( "AttributeConverter not applied" ); - } - AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type ); - assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); - SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor(); - assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() ); + assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) ); + + final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type; + + assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) ); + assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) ); + + final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor(); + assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); @@ -405,23 +412,25 @@ public class AttributeConverterTest extends BaseUnitTestCase { .build(); // first lets validate that the converter was applied... - PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() ); - Property nameProp = tester.getProperty( "convertibleEnum" ); - SimpleValue nameValue = (SimpleValue) nameProp.getValue(); - Type type = nameValue.getType(); + final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() ); + final Property nameProp = tester.getProperty( "convertibleEnum" ); + final BasicValue nameValue = (BasicValue) nameProp.getValue(); + final Type type = nameValue.getType(); assertNotNull( type ); - assertTyping( BasicType.class, type ); - if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) { - fail( "AttributeConverter not applied" ); - } - AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); - assertTyping( EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor() ); - if (metadata.getDatabase().getDialect() instanceof HANACloudColumnStoreDialect) { - assertEquals( Types.NVARCHAR, basicType.getSqlTypeDescriptor().getSqlType() ); + assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) ); + + final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type; + + assertThat( typeAdapter.getDomainJtd(), instanceOf( EnumJavaTypeDescriptor.class ) ); + + final int expectedJdbcTypeCode; + if ( metadata.getDatabase().getDialect() instanceof HANAColumnStoreDialect ) { + expectedJdbcTypeCode = Types.NVARCHAR; } else { - assertEquals( Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType() ); + expectedJdbcTypeCode = Types.VARCHAR; } + assertThat( typeAdapter.getSqlTypeDescriptor().getJdbcTypeCode(), is( expectedJdbcTypeCode ) ); // then lets build the SF and verify its use... final SessionFactory sf = metadata.buildSessionFactory(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/PackagePrivateAttributeConverterEntityManagerFactoryTest.java b/hibernate-core/src/test/java/org/hibernate/test/converter/PackagePrivateAttributeConverterEntityManagerFactoryTest.java index 67a2ae9780..c3b8bb6028 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/PackagePrivateAttributeConverterEntityManagerFactoryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/PackagePrivateAttributeConverterEntityManagerFactoryTest.java @@ -6,8 +6,6 @@ */ package org.hibernate.test.converter; -import java.util.Arrays; -import java.util.List; import javax.persistence.AttributeConverter; import javax.persistence.Convert; import javax.persistence.Converter; @@ -15,52 +13,55 @@ import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Tuple; -import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.NotImplementedYet; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; import static org.junit.Assert.assertEquals; /** * @author Vlad Mihalcea */ @TestForIssue( jiraKey = "HHH-10778" ) -public class PackagePrivateAttributeConverterEntityManagerFactoryTest extends BaseEntityManagerFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Tester.class }; - } +@DomainModel( annotatedClasses = PackagePrivateAttributeConverterEntityManagerFactoryTest.Tester.class ) +@SessionFactory +public class PackagePrivateAttributeConverterEntityManagerFactoryTest { + public final String sql = "select code from Tester where id = :id"; @Test - public void test() { - doInJPA( this::entityManagerFactory, entityManager -> { - Tester tester = new Tester(); - tester.setId( 1L ); - tester.setCode( 123 ); + @NotImplementedYet( strict = false, reason = "Support for passing `resultType` to `#createNativeQuery` not yet implemented" ) + public void test(SessionFactoryScope scope) { + scope.inTransaction( + (session) -> { + final Tester tester = new Tester(); + tester.setId( 1L ); + tester.setCode( 123 ); - entityManager.persist( tester ); - } ); + session.persist( tester ); + } + ); - doInJPA( this::entityManagerFactory, entityManager -> { - Tuple tuple = (Tuple) entityManager.createNativeQuery( - "select code " + - "from Tester " + - "where id = :id", Tuple.class ) - .setParameter( "id", 1L ) - .getSingleResult(); + scope.inTransaction( + (session) -> { + final Tuple tuple = (Tuple) session.createNativeQuery( sql, Tuple.class ) + .setParameter( "id", 1L ) + .getSingleResult(); + assertEquals( "123", tuple.get( "code" ) ); - assertEquals( "123", tuple.get( "code" ) ); + final Tester tester = session.find( Tester.class, 1L ); + assertEquals( 123, (int) tester.getCode() ); + } + ); + } - Tester tester = entityManager.find( Tester.class, 1L ); - - assertEquals( 123, (int) tester.getCode() ); - } ); + @AfterEach + public void dropTestData(SessionFactoryScope scope) { + scope.inTransaction( (session) -> session.createQuery( "delete Tester" ).executeUpdate() ); } // Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~