Skip to content

Commit 7cc0c83

Browse files
committed
HHH-14881 Allow providing attribute converters through CDI when configured through orm.xml
1 parent fc63699 commit 7cc0c83

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/JPAXMLOverriddenMetadataProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider
5454

5555
public JPAXMLOverriddenMetadataProvider(BootstrapContext bootstrapContext) {
5656
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
57-
this.xmlContext = new XMLContext( classLoaderAccess );
57+
this.xmlContext = new XMLContext( bootstrapContext );
5858
this.xmlMappingEnabled = bootstrapContext.getMetadataBuildingOptions().isXmlMappingEnabled();
5959
}
6060

hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/internal/XMLContext.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import javax.persistence.AttributeConverter;
1616

1717
import org.hibernate.AnnotationException;
18-
import org.hibernate.boot.AttributeConverterInfo;
18+
import org.hibernate.boot.internal.ClassmateContext;
1919
import org.hibernate.boot.jaxb.mapping.spi.JaxbConverter;
2020
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
2121
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener;
@@ -25,10 +25,11 @@
2525
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults;
2626
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata;
2727
import org.hibernate.boot.jaxb.mapping.spi.ManagedType;
28+
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
29+
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
2830
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
2931
import org.hibernate.boot.spi.BootstrapContext;
3032
import org.hibernate.boot.spi.ClassLoaderAccess;
31-
import org.hibernate.cfg.AttributeConverterDefinition;
3233
import org.hibernate.cfg.annotations.reflection.AttributeConverterDefinitionCollector;
3334
import org.hibernate.internal.CoreLogging;
3435
import org.hibernate.internal.CoreMessageLogger;
@@ -44,6 +45,7 @@ public class XMLContext implements Serializable {
4445
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( XMLContext.class );
4546

4647
private final ClassLoaderAccess classLoaderAccess;
48+
private final ClassmateContext classmateContext;
4749

4850
private Default globalDefaults;
4951
private final Map<String, ManagedType> managedTypeOverride = new HashMap<>();
@@ -53,16 +55,9 @@ public class XMLContext implements Serializable {
5355
private final List<String> defaultEntityListeners = new ArrayList<>();
5456
private boolean hasContext = false;
5557

56-
/**
57-
* @deprecated Use {@link #XMLContext(BootstrapContext)} instead.
58-
*/
59-
@Deprecated
60-
public XMLContext(ClassLoaderAccess classLoaderAccess) {
61-
this.classLoaderAccess = classLoaderAccess;
62-
}
63-
6458
public XMLContext(BootstrapContext bootstrapContext) {
6559
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
60+
this.classmateContext = bootstrapContext.getClassmateContext();
6661
}
6762

6863
/**
@@ -177,8 +172,8 @@ private void setLocalAttributeConverterDefinitions(List<JaxbConverter> converter
177172
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
178173
buildSafeClassName( className, packageName )
179174
);
180-
attributeConverterInfoList.add(
181-
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )
175+
converterDescriptors.add(
176+
new ClassBasedConverterDescriptor( attributeConverterClass, autoApply, classmateContext )
182177
);
183178
}
184179
catch (ClassLoadingException e) {
@@ -227,13 +222,13 @@ public boolean hasContext() {
227222
return hasContext;
228223
}
229224

230-
private List<AttributeConverterInfo> attributeConverterInfoList = new ArrayList<>();
225+
private List<ConverterDescriptor> converterDescriptors = new ArrayList<>();
231226

232227
public void applyDiscoveredAttributeConverters(AttributeConverterDefinitionCollector collector) {
233-
for ( AttributeConverterInfo info : attributeConverterInfoList ) {
234-
collector.addAttributeConverter( info );
228+
for ( ConverterDescriptor descriptor : converterDescriptors ) {
229+
collector.addAttributeConverter( descriptor );
235230
}
236-
attributeConverterInfoList.clear();
231+
converterDescriptors.clear();
237232
}
238233

239234
public static class Default implements Serializable {

0 commit comments

Comments
 (0)