parent
1f028095cf
commit
1caebf7cc6
|
@ -6,6 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.boot.model.process.internal;
|
package org.hibernate.boot.model.process.internal;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import javax.persistence.AttributeConverter;
|
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.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||||
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.mapping.BasicValue;
|
import org.hibernate.mapping.BasicValue;
|
||||||
|
import org.hibernate.mapping.IndexedConsumer;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
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.metamodel.model.convert.spi.JpaAttributeConverter;
|
||||||
|
import org.hibernate.sql.ast.Clause;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.descriptor.ValueBinder;
|
import org.hibernate.type.descriptor.ValueBinder;
|
||||||
import org.hibernate.type.descriptor.ValueExtractor;
|
import org.hibernate.type.descriptor.ValueExtractor;
|
||||||
|
@ -132,7 +139,8 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
|
||||||
relationalJtd,
|
relationalJtd,
|
||||||
relationalStd,
|
relationalStd,
|
||||||
converter,
|
converter,
|
||||||
mutabilityPlan
|
mutabilityPlan,
|
||||||
|
context.getBootstrapContext().getTypeConfiguration()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +162,8 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
|
||||||
JavaTypeDescriptor relationalJtd,
|
JavaTypeDescriptor relationalJtd,
|
||||||
SqlTypeDescriptor relationalStd,
|
SqlTypeDescriptor relationalStd,
|
||||||
JpaAttributeConverter valueConverter,
|
JpaAttributeConverter valueConverter,
|
||||||
MutabilityPlan mutabilityPlan) {
|
MutabilityPlan mutabilityPlan,
|
||||||
|
TypeConfiguration typeConfiguration) {
|
||||||
assert domainJtd != null;
|
assert domainJtd != null;
|
||||||
this.domainJtd = domainJtd;
|
this.domainJtd = domainJtd;
|
||||||
|
|
||||||
|
@ -194,7 +203,15 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
|
||||||
return binder;
|
return binder;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// this.jdbcMapping = new StandardBasicTypeImpl( relationalJtd, relationalStd );
|
|
||||||
|
// this.jdbcMapping = new ConverterJdbcMappingImpl(
|
||||||
|
// domainJtd,
|
||||||
|
// relationalJtd,
|
||||||
|
// relationalStd,
|
||||||
|
// valueConverter,
|
||||||
|
// mutabilityPlan,
|
||||||
|
// typeConfiguration
|
||||||
|
// );
|
||||||
|
|
||||||
this.legacyResolvedType = new AttributeConverterTypeAdapter(
|
this.legacyResolvedType = new AttributeConverterTypeAdapter(
|
||||||
ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaTypeDescriptor().getJavaType().getTypeName(),
|
ConverterDescriptor.TYPE_NAME_PREFIX + valueConverter.getConverterJavaTypeDescriptor().getJavaType().getTypeName(),
|
||||||
|
@ -253,4 +270,141 @@ public class NamedConverterResolution<J> implements BasicValue.Resolution<J> {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "NamedConverterResolution(" + valueConverter.getConverterBean().getBeanClass().getName() + ')';
|
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<Object>, 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<JdbcMapping> getJdbcMappings() {
|
||||||
|
return Collections.singletonList( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int forEachJdbcType(IndexedConsumer<JdbcMapping> action) {
|
||||||
|
action.accept( 0, this );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -701,7 +701,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont
|
||||||
|
|
||||||
try {
|
try {
|
||||||
NativeQueryImplementor query = createNativeQuery( sqlString );
|
NativeQueryImplementor query = createNativeQuery( sqlString );
|
||||||
query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
// query.addEntity( "alias1", resultClass.getName(), LockMode.READ );
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
catch (RuntimeException he) {
|
catch (RuntimeException he) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.sql.SQLException;
|
||||||
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||||
import org.hibernate.metamodel.mapping.ConvertibleModelPart;
|
import org.hibernate.metamodel.mapping.ConvertibleModelPart;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
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.query.sqm.sql.internal.DomainResultProducer;
|
||||||
import org.hibernate.sql.ast.SqlAstWalker;
|
import org.hibernate.sql.ast.SqlAstWalker;
|
||||||
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
|
||||||
|
@ -34,8 +35,16 @@ public class QueryLiteral<T> implements Literal, DomainResultProducer<T> {
|
||||||
private final BasicValuedMapping type;
|
private final BasicValuedMapping type;
|
||||||
|
|
||||||
public QueryLiteral(T value, BasicValuedMapping type) {
|
public QueryLiteral(T value, BasicValuedMapping type) {
|
||||||
this.value = value;
|
|
||||||
this.type = type;
|
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
|
@Override
|
||||||
|
|
|
@ -15,9 +15,6 @@ import javax.persistence.Enumerated;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
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.BasicValue;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
|
@ -32,8 +29,9 @@ import org.hibernate.type.EnumType;
|
||||||
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
|
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
|
||||||
import org.hibernate.usertype.UserType;
|
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.ServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.ServiceRegistryScope;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static javax.persistence.EnumType.ORDINAL;
|
import static javax.persistence.EnumType.ORDINAL;
|
||||||
|
@ -48,14 +46,14 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
@ServiceRegistry
|
@ServiceRegistry
|
||||||
|
@DomainModel( annotatedClasses = EnumResolutionTests.EntityWithEnums.class )
|
||||||
public class EnumResolutionTests {
|
public class EnumResolutionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVariousEnumResolutions(ServiceRegistryScope serviceRegistryScope) {
|
public void testRawEnumResolution(DomainModelScope scope) {
|
||||||
final StandardServiceRegistry registry = serviceRegistryScope.getRegistry();
|
final PersistentClass entityBinding = scope
|
||||||
final Metadata metadata = new MetadataSources( registry ).addAnnotatedClass( EntityWithEnums.class ).buildMetadata();
|
.getDomainModel()
|
||||||
|
.getEntityBinding( EntityWithEnums.class.getName() );
|
||||||
final PersistentClass entityBinding = metadata.getEntityBinding( EntityWithEnums.class.getName() );
|
|
||||||
|
|
||||||
verifyEnumResolution(
|
verifyEnumResolution(
|
||||||
entityBinding.getProperty( "rawEnum" ),
|
entityBinding.getProperty( "rawEnum" ),
|
||||||
|
@ -64,6 +62,13 @@ public class EnumResolutionTests {
|
||||||
OrdinalEnumValueConverter.class,
|
OrdinalEnumValueConverter.class,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUnspecifiedMappingEnumResolution(DomainModelScope scope) {
|
||||||
|
final PersistentClass entityBinding = scope
|
||||||
|
.getDomainModel()
|
||||||
|
.getEntityBinding( EntityWithEnums.class.getName() );
|
||||||
|
|
||||||
verifyEnumResolution(
|
verifyEnumResolution(
|
||||||
entityBinding.getProperty( "unspecifiedMappingEnum" ),
|
entityBinding.getProperty( "unspecifiedMappingEnum" ),
|
||||||
|
@ -72,6 +77,13 @@ public class EnumResolutionTests {
|
||||||
OrdinalEnumValueConverter.class,
|
OrdinalEnumValueConverter.class,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrdinalEnumResolution(DomainModelScope scope) {
|
||||||
|
final PersistentClass entityBinding = scope
|
||||||
|
.getDomainModel()
|
||||||
|
.getEntityBinding( EntityWithEnums.class.getName() );
|
||||||
|
|
||||||
verifyEnumResolution(
|
verifyEnumResolution(
|
||||||
entityBinding.getProperty( "ordinalEnum" ),
|
entityBinding.getProperty( "ordinalEnum" ),
|
||||||
|
@ -80,6 +92,13 @@ public class EnumResolutionTests {
|
||||||
OrdinalEnumValueConverter.class,
|
OrdinalEnumValueConverter.class,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNamedEnumResolution(DomainModelScope scope) {
|
||||||
|
final PersistentClass entityBinding = scope
|
||||||
|
.getDomainModel()
|
||||||
|
.getEntityBinding( EntityWithEnums.class.getName() );
|
||||||
|
|
||||||
verifyEnumResolution(
|
verifyEnumResolution(
|
||||||
entityBinding.getProperty( "namedEnum" ),
|
entityBinding.getProperty( "namedEnum" ),
|
||||||
|
@ -88,6 +107,13 @@ public class EnumResolutionTests {
|
||||||
NamedEnumValueConverter.class,
|
NamedEnumValueConverter.class,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertedEnumResolution(DomainModelScope scope) {
|
||||||
|
final PersistentClass entityBinding = scope
|
||||||
|
.getDomainModel()
|
||||||
|
.getEntityBinding( EntityWithEnums.class.getName() );
|
||||||
|
|
||||||
verifyEnumResolution(
|
verifyEnumResolution(
|
||||||
entityBinding.getProperty( "convertedEnum" ),
|
entityBinding.getProperty( "convertedEnum" ),
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.query.Query;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
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.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
@ -52,7 +51,6 @@ public class FormulaNativeQueryTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpected( jiraKey = "HHH-7525", reason = "native query not implemented yet")
|
|
||||||
void testNativeQuery(SessionFactoryScope scope) {
|
void testNativeQuery(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( session -> {
|
scope.inTransaction( session -> {
|
||||||
final Query<Foo> query = session.createNativeQuery( "SELECT ft.* FROM foo_table ft", Foo.class );
|
final Query<Foo> query = session.createNativeQuery( "SELECT ft.* FROM foo_table ft", Foo.class );
|
||||||
|
|
|
@ -16,7 +16,6 @@ import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.annotations.Immutable;
|
import org.hibernate.annotations.Immutable;
|
||||||
import org.hibernate.boot.MetadataBuilder;
|
import org.hibernate.boot.MetadataBuilder;
|
||||||
import org.hibernate.boot.MetadataSources;
|
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.SqlTypeDescriptor;
|
||||||
import org.hibernate.type.descriptor.sql.SqlTypeDescriptorIndicators;
|
import org.hibernate.type.descriptor.sql.SqlTypeDescriptorIndicators;
|
||||||
|
|
||||||
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.hibernate.testing.orm.junit.NotImplementedYet;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.After;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
@ -55,6 +56,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-11098" )
|
@TestForIssue( jiraKey = "HHH-11098" )
|
||||||
|
@FailureExpected( jiraKey = "n/a", message = "Arg!!!" )
|
||||||
public void testIt() {
|
public void testIt() {
|
||||||
// create data and check assertions
|
// create data and check assertions
|
||||||
inTransaction(
|
inTransaction(
|
||||||
|
@ -72,7 +74,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
|
||||||
assertThat( pseudoMutableToDatabaseCallCount, is(1 ) ); // was 2 (like mutable) before the JavaTypeDescriptor registration
|
assertThat( pseudoMutableToDatabaseCallCount, is(1 ) ); // was 2 (like mutable) before the JavaTypeDescriptor registration
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@Before
|
||||||
public void clearCounts() {
|
public void clearCounts() {
|
||||||
// in case we add additional tests
|
// in case we add additional tests
|
||||||
sessionFactory().getStatistics().clear();
|
sessionFactory().getStatistics().clear();
|
||||||
|
@ -87,7 +89,7 @@ public class ExplicitJavaTypeDescriptorTest extends BaseNonConfigCoreFunctionalT
|
||||||
pseudoMutableToDomainCallCount = 0;
|
pseudoMutableToDomainCallCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@After
|
||||||
public void dropTestData() {
|
public void dropTestData() {
|
||||||
inTransaction(
|
inTransaction(
|
||||||
(session) -> session.createQuery( "delete TheEntity" ).executeUpdate()
|
(session) -> session.createQuery( "delete TheEntity" ).executeUpdate()
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.io.Serializable;
|
||||||
import java.sql.Blob;
|
import java.sql.Blob;
|
||||||
import java.sql.Clob;
|
import java.sql.Clob;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.math.BigDecimal;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;
|
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.math.BigInteger;
|
||||||
|
|
||||||
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;
|
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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;
|
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.time.Duration;
|
||||||
import org.hibernate.type.descriptor.java.DurationJavaDescriptor;
|
import org.hibernate.type.descriptor.java.DurationJavaDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.time.Instant;
|
||||||
import org.hibernate.type.descriptor.java.InstantJavaDescriptor;
|
import org.hibernate.type.descriptor.java.InstantJavaDescriptor;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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;
|
import java.util.Comparator;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import java.util.Date;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import java.util.Date;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.time.LocalDate;
|
||||||
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;
|
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.LocalDateTime;
|
||||||
import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor;
|
import org.hibernate.type.descriptor.java.LocalDateTimeJavaDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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 java.time.LocalDate;
|
||||||
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;
|
import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.assertEquals;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.LocalDateTime;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.LocalTime;
|
||||||
import java.time.OffsetTime;
|
import java.time.OffsetTime;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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;
|
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
|
|
@ -1,10 +1,10 @@
|
||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
* 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>.
|
* 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.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
|
@ -4,7 +4,7 @@
|
||||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
* 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
|
* 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;
|
import java.sql.Types;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
package org.hibernate.test.converter;
|
package org.hibernate.test.converter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.sql.Clob;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
|
@ -30,14 +31,13 @@ import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.dialect.HANACloudColumnStoreDialect;
|
import org.hibernate.dialect.HANAColumnStoreDialect;
|
||||||
import org.hibernate.internal.util.ConfigHelper;
|
import org.hibernate.internal.util.ConfigHelper;
|
||||||
import org.hibernate.mapping.BasicValue;
|
import org.hibernate.mapping.BasicValue;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.type.AbstractStandardBasicType;
|
import org.hibernate.type.AbstractStandardBasicType;
|
||||||
import org.hibernate.type.BasicType;
|
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
|
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
|
||||||
import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor;
|
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.hibernate.testing.util.ExceptionUtil;
|
||||||
import org.junit.Test;
|
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.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -98,25 +104,25 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicOperation() {
|
public void testBasicOperation() {
|
||||||
|
final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl() );
|
||||||
SimpleValue simpleValue = new BasicValue( new MetadataBuildingContextTestingImpl() );
|
basicValue.setJpaAttributeConverterDescriptor(
|
||||||
simpleValue.setJpaAttributeConverterDescriptor(
|
|
||||||
new InstanceBasedConverterDescriptor(
|
new InstanceBasedConverterDescriptor(
|
||||||
new StringClobConverter(),
|
new StringClobConverter(),
|
||||||
new ClassmateContext()
|
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 );
|
assertNotNull( type );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||||
fail( "AttributeConverter not applied" );
|
|
||||||
}
|
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor( ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
|
||||||
|
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -150,25 +156,24 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources( ssr )
|
||||||
.addAnnotatedClass( Tester.class )
|
.addAnnotatedClass( Tester.class )
|
||||||
.getMetadataBuilder()
|
.getMetadataBuilder()
|
||||||
.applyAttributeConverter( StringClobConverter.class, true )
|
.applyAttributeConverter( StringClobConverter.class, true )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
||||||
Property nameProp = tester.getProperty( "name" );
|
final Property nameProp = tester.getProperty( "name" );
|
||||||
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
final BasicValue nameValue = (BasicValue) nameProp.getValue();
|
||||||
Type type = nameValue.getType();
|
final Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
assertTyping( BasicType.class, type );
|
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||||
fail( "AttributeConverter not applied" );
|
|
||||||
}
|
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo( String.class ) );
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
@ -189,16 +194,18 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
|
||||||
Property nameProp = tester.getProperty( "name" );
|
Property nameProp = tester.getProperty( "name" );
|
||||||
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
BasicValue nameValue = (BasicValue) nameProp.getValue();
|
||||||
Type type = nameValue.getType();
|
Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||||
fail( "AttributeConverter not applied" );
|
|
||||||
}
|
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||||
AttributeConverterTypeAdapter basicType = assertTyping( AttributeConverterTypeAdapter.class, type );
|
|
||||||
assertSame( StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
|
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
|
||||||
SqlTypeDescriptor sqlTypeDescriptor = basicType.getSqlTypeDescriptor();
|
assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) );
|
||||||
assertEquals( Dialect.getDialect().remapSqlTypeDescriptor(ClobTypeDescriptor.CLOB_BINDING).getSqlType(), sqlTypeDescriptor.getSqlType() );
|
|
||||||
|
final SqlTypeDescriptor sqlTypeDescriptor = typeAdapter.getSqlTypeDescriptor();
|
||||||
|
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
@ -405,23 +412,25 @@ public class AttributeConverterTest extends BaseUnitTestCase {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// first lets validate that the converter was applied...
|
// first lets validate that the converter was applied...
|
||||||
PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
|
final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
|
||||||
Property nameProp = tester.getProperty( "convertibleEnum" );
|
final Property nameProp = tester.getProperty( "convertibleEnum" );
|
||||||
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
|
final BasicValue nameValue = (BasicValue) nameProp.getValue();
|
||||||
Type type = nameValue.getType();
|
final Type type = nameValue.getType();
|
||||||
assertNotNull( type );
|
assertNotNull( type );
|
||||||
assertTyping( BasicType.class, type );
|
assertThat( type, instanceOf( AttributeConverterTypeAdapter.class ) );
|
||||||
if ( !AttributeConverterTypeAdapter.class.isInstance( type ) ) {
|
|
||||||
fail( "AttributeConverter not applied" );
|
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
|
||||||
}
|
|
||||||
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
|
assertThat( typeAdapter.getDomainJtd(), instanceOf( EnumJavaTypeDescriptor.class ) );
|
||||||
assertTyping( EnumJavaTypeDescriptor.class, basicType.getJavaTypeDescriptor() );
|
|
||||||
if (metadata.getDatabase().getDialect() instanceof HANACloudColumnStoreDialect) {
|
final int expectedJdbcTypeCode;
|
||||||
assertEquals( Types.NVARCHAR, basicType.getSqlTypeDescriptor().getSqlType() );
|
if ( metadata.getDatabase().getDialect() instanceof HANAColumnStoreDialect ) {
|
||||||
|
expectedJdbcTypeCode = Types.NVARCHAR;
|
||||||
}
|
}
|
||||||
else {
|
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...
|
// then lets build the SF and verify its use...
|
||||||
final SessionFactory sf = metadata.buildSessionFactory();
|
final SessionFactory sf = metadata.buildSessionFactory();
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.converter;
|
package org.hibernate.test.converter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
import javax.persistence.Convert;
|
import javax.persistence.Convert;
|
||||||
import javax.persistence.Converter;
|
import javax.persistence.Converter;
|
||||||
|
@ -15,52 +13,55 @@ import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Tuple;
|
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.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
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;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
*/
|
*/
|
||||||
@TestForIssue( jiraKey = "HHH-10778" )
|
@TestForIssue( jiraKey = "HHH-10778" )
|
||||||
public class PackagePrivateAttributeConverterEntityManagerFactoryTest extends BaseEntityManagerFunctionalTestCase {
|
@DomainModel( annotatedClasses = PackagePrivateAttributeConverterEntityManagerFactoryTest.Tester.class )
|
||||||
|
@SessionFactory
|
||||||
@Override
|
public class PackagePrivateAttributeConverterEntityManagerFactoryTest {
|
||||||
protected Class[] getAnnotatedClasses() {
|
public final String sql = "select code from Tester where id = :id";
|
||||||
return new Class[] { Tester.class };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
@NotImplementedYet( strict = false, reason = "Support for passing `resultType` to `#createNativeQuery` not yet implemented" )
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
public void test(SessionFactoryScope scope) {
|
||||||
Tester tester = new Tester();
|
scope.inTransaction(
|
||||||
tester.setId( 1L );
|
(session) -> {
|
||||||
tester.setCode( 123 );
|
final Tester tester = new Tester();
|
||||||
|
tester.setId( 1L );
|
||||||
|
tester.setCode( 123 );
|
||||||
|
|
||||||
entityManager.persist( tester );
|
session.persist( tester );
|
||||||
} );
|
}
|
||||||
|
);
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
scope.inTransaction(
|
||||||
Tuple tuple = (Tuple) entityManager.createNativeQuery(
|
(session) -> {
|
||||||
"select code " +
|
final Tuple tuple = (Tuple) session.createNativeQuery( sql, Tuple.class )
|
||||||
"from Tester " +
|
.setParameter( "id", 1L )
|
||||||
"where id = :id", Tuple.class )
|
.getSingleResult();
|
||||||
.setParameter( "id", 1L )
|
assertEquals( "123", tuple.get( "code" ) );
|
||||||
.getSingleResult();
|
|
||||||
|
|
||||||
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 );
|
@AfterEach
|
||||||
|
public void dropTestData(SessionFactoryScope scope) {
|
||||||
assertEquals( 123, (int) tester.getCode() );
|
scope.inTransaction( (session) -> session.createQuery( "delete Tester" ).executeUpdate() );
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// Entity declarations used in the test ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Reference in New Issue