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()
|
||||
);
|
||||
|
||||
final Class elementClass = getMappings().getReflectionManager().toClass( elementXClass );
|
||||
final Class elementClass = determineElementClass( elementXClass );
|
||||
if ( elementClass != null ) {
|
||||
for ( AttributeConverterDefinition attributeConverterDefinition : getMappings().getAttributeConverters() ) {
|
||||
if ( ! attributeConverterDefinition.isAutoApply() ) {
|
||||
continue;
|
||||
|
@ -235,10 +236,40 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder {
|
|||
return attributeConverterDefinition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
protected AttributeConversionInfo locateAttributeConversionInfo(XProperty property) {
|
||||
if ( canElementBeConverted && canKeyBeConverted ) {
|
||||
|
|
|
@ -1274,6 +1274,15 @@ public abstract class CollectionBinder {
|
|||
if ( BinderHelper.PRIMITIVE_NAMES.contains( collType.getName() ) ) {
|
||||
classType = AnnotatedClassType.NONE;
|
||||
elementClass = null;
|
||||
|
||||
holder = PropertyHolderBuilder.buildPropertyHolder(
|
||||
collValue,
|
||||
collValue.getRole(),
|
||||
null,
|
||||
property,
|
||||
parentPropertyHolder,
|
||||
mappings
|
||||
);
|
||||
}
|
||||
else {
|
||||
elementClass = collType;
|
||||
|
|
|
@ -109,7 +109,7 @@ public class CollectionElementConversionTest extends BaseUnitTestCase {
|
|||
@CollectionTable(
|
||||
name = "cust_color",
|
||||
joinColumns = @JoinColumn(name = "cust_fk", nullable = false),
|
||||
uniqueConstraints = @UniqueConstraint(columnNames = { "customer_fk", "color" })
|
||||
uniqueConstraints = @UniqueConstraint(columnNames = { "cust_fk", "color" })
|
||||
)
|
||||
@Column(name = "color", nullable = false)
|
||||
private Set<ColorType> colors = new HashSet<ColorType>();
|
||||
|
|
Loading…
Reference in New Issue