HHH-8529 - AttributeConverter not applied to @ElementCollection
This commit is contained in:
parent
4473f0302f
commit
a1ff3a29cb
|
@ -220,7 +220,8 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder {
|
||||||
collection.getRole()
|
collection.getRole()
|
||||||
);
|
);
|
||||||
|
|
||||||
final Class elementClass = getMappings().getReflectionManager().toClass( elementXClass );
|
final Class elementClass = determineElementClass( elementXClass );
|
||||||
|
if ( elementClass != null ) {
|
||||||
for ( AttributeConverterDefinition attributeConverterDefinition : getMappings().getAttributeConverters() ) {
|
for ( AttributeConverterDefinition attributeConverterDefinition : getMappings().getAttributeConverters() ) {
|
||||||
if ( ! attributeConverterDefinition.isAutoApply() ) {
|
if ( ! attributeConverterDefinition.isAutoApply() ) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -235,10 +236,40 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder {
|
||||||
return attributeConverterDefinition;
|
return attributeConverterDefinition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Class determineElementClass(XClass elementXClass) {
|
||||||
|
if ( elementXClass != null ) {
|
||||||
|
try {
|
||||||
|
return getMappings().getReflectionManager().toClass( elementXClass );
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.debugf(
|
||||||
|
"Unable to resolve XClass [%s] to Class for collection elements [%s]",
|
||||||
|
elementXClass.getName(),
|
||||||
|
collection.getRole()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( collection.getElement() != null ) {
|
||||||
|
if ( collection.getElement().getType() != null ) {
|
||||||
|
return collection.getElement().getType().getReturnedClass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// currently this is called from paths where the element type really should be known,
|
||||||
|
// so log the fact that we could not resolve the collection element info
|
||||||
|
log.debugf(
|
||||||
|
"Unable to resolve element information for collection [%s]",
|
||||||
|
collection.getRole()
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AttributeConversionInfo locateAttributeConversionInfo(XProperty property) {
|
protected AttributeConversionInfo locateAttributeConversionInfo(XProperty property) {
|
||||||
if ( canElementBeConverted && canKeyBeConverted ) {
|
if ( canElementBeConverted && canKeyBeConverted ) {
|
||||||
|
|
|
@ -1274,6 +1274,15 @@ public abstract class CollectionBinder {
|
||||||
if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
|
if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
|
||||||
classType = AnnotatedClassType.NONE;
|
classType = AnnotatedClassType.NONE;
|
||||||
elementClass = null;
|
elementClass = null;
|
||||||
|
|
||||||
|
holder = PropertyHolderBuilder.buildPropertyHolder(
|
||||||
|
collValue,
|
||||||
|
collValue.getRole(),
|
||||||
|
null,
|
||||||
|
property,
|
||||||
|
parentPropertyHolder,
|
||||||
|
mappings
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
elementClass = collType;
|
elementClass = collType;
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class CollectionElementConversionTest extends BaseUnitTestCase {
|
||||||
@CollectionTable(
|
@CollectionTable(
|
||||||
name = "cust_color",
|
name = "cust_color",
|
||||||
joinColumns = @JoinColumn(name = "cust_fk", nullable = false),
|
joinColumns = @JoinColumn(name = "cust_fk", nullable = false),
|
||||||
uniqueConstraints = @UniqueConstraint(columnNames = { "customer_fk", "color" })
|
uniqueConstraints = @UniqueConstraint(columnNames = { "cust_fk", "color" })
|
||||||
)
|
)
|
||||||
@Column(name = "color", nullable = false)
|
@Column(name = "color", nullable = false)
|
||||||
private Set<ColorType> colors = new HashSet<ColorType>();
|
private Set<ColorType> colors = new HashSet<ColorType>();
|
||||||
|
|
Loading…
Reference in New Issue