Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ private static void processEntityMetadata(

XmlAnnotationHelper.applyTable( jaxbEntity.getTable(), classDetails, xmlDocumentContext );
XmlAnnotationHelper.applySecondaryTables( jaxbEntity.getSecondaryTables(), classDetails, xmlDocumentContext );

final JaxbAttributesContainerImpl attributes = jaxbEntity.getAttributes();
if ( attributes != null ) {
processIdMappings(
Expand All @@ -234,6 +233,9 @@ private static void processEntityMetadata(
xmlDocumentContext
);
}

XmlAnnotationHelper.applyConverts( jaxbEntity.getConverts(), classDetails, xmlDocumentContext );

AttributeProcessor.processAttributeOverrides(
jaxbEntity.getAttributeOverrides(),
classDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
import static org.hibernate.boot.models.JpaAnnotations.CHECK_CONSTRAINT;
import static org.hibernate.boot.models.JpaAnnotations.COLUMN;
import static org.hibernate.boot.models.JpaAnnotations.CONVERT;
import static org.hibernate.boot.models.JpaAnnotations.CONVERTS;
import static org.hibernate.boot.models.JpaAnnotations.EXCLUDE_DEFAULT_LISTENERS;
import static org.hibernate.boot.models.JpaAnnotations.EXCLUDE_SUPERCLASS_LISTENERS;
import static org.hibernate.boot.models.JpaAnnotations.INDEX;
Expand Down Expand Up @@ -804,6 +805,28 @@ public static void applyConvert(
transferConvertDetails( jaxbConvert, annotation, null, xmlDocumentContext );
}

public static void applyConverts(
List<JaxbConvertImpl> jaxbConverts,
MutableAnnotationTarget target,
XmlDocumentContext xmlDocumentContext){
if ( isEmpty( jaxbConverts ) ) {
return;
}

final ConvertsJpaAnnotation convertsUsage = (ConvertsJpaAnnotation) target.replaceAnnotationUsage(
CONVERT,
CONVERTS,
xmlDocumentContext.getModelBuildingContext()
);

final Convert[] convertUsages = new Convert[jaxbConverts.size()];
convertsUsage.value( convertUsages );

for ( int i = 0; i < jaxbConverts.size(); i++ ) {
convertUsages[i] = transformConvert( jaxbConverts.get( i ), null, xmlDocumentContext );
}
}

public static void applyConverts(
List<JaxbConvertImpl> jaxbConverts,
String namePrefix,
Expand All @@ -815,7 +838,7 @@ public static void applyConverts(

final ConvertsJpaAnnotation convertsUsage = (ConvertsJpaAnnotation) memberDetails.replaceAnnotationUsage(
CONVERT,
JpaAnnotations.CONVERTS,
CONVERTS,
xmlDocumentContext.getModelBuildingContext()
);
final Convert[] convertUsages = new Convert[jaxbConverts.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.StringJavaType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.internal.BasicTypeImpl;
import org.hibernate.type.internal.ConvertedBasicTypeImpl;

import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -66,10 +67,27 @@ public void testDefinitionAtAttributeLevel(ServiceRegistryScope scope) {

PersistentClass pc = metadata.getEntityBinding( TheEntity.class.getName() );
BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType();
assertTyping( BasicTypeImpl.class, type ); // Should not be ConvertedBasicTypeImpl in particular
assertTyping( StringJavaType.class, type.getJavaTypeDescriptor() );
assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), type.getJdbcType() );
}

/**
* A baseline test, with an explicit @Convert annotation at entity level that should be in effect
*/
@Test
public void baselineAtEntityLevel(ServiceRegistryScope scope) {
Metadata metadata = new MetadataSources( scope.getRegistry() )
.addAnnotatedClass( TheEntity2.class )
.buildMetadata();

PersistentClass pc = metadata.getEntityBinding( TheEntity2.class.getName() );
Type type = pc.getProperty( "it" ).getType();
ConvertedBasicTypeImpl adapter = assertTyping( ConvertedBasicTypeImpl.class, type );
final JpaAttributeConverter converter = (JpaAttributeConverter) adapter.getValueConverter();
assertTrue( SillyStringConverter.class.isAssignableFrom( converter.getConverterJavaType().getJavaTypeClass() ) );
}

/**
* Test outcome of applying overrides via orm.xml, specifically at the entity level
*/
Expand All @@ -85,6 +103,7 @@ public void testDefinitionAtEntityLevel(ServiceRegistryScope scope) {

PersistentClass pc = metadata.getEntityBinding( TheEntity2.class.getName() );
BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType();
assertTyping( BasicTypeImpl.class, type ); // Should not be ConvertedBasicTypeImpl in particular
assertTyping( StringJavaType.class, type.getJavaTypeDescriptor() );
assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), type.getJdbcType() );
}
Expand Down
Loading