Skip to content

Commit

Permalink
HHH-8529 - AttributeConverter not applied to @ElementCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Sep 21, 2013
1 parent 4473f03 commit a1ff3a2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
Expand Up @@ -220,22 +220,53 @@ public AttributeConverterDefinition resolveElementAttributeConverterDefinition(X
collection.getRole()
);

final Class elementClass = getMappings().getReflectionManager().toClass( elementXClass );
for ( AttributeConverterDefinition attributeConverterDefinition : getMappings().getAttributeConverters() ) {
if ( ! attributeConverterDefinition.isAutoApply() ) {
continue;
final Class elementClass = determineElementClass( elementXClass );
if ( elementClass != null ) {
for ( AttributeConverterDefinition attributeConverterDefinition : getMappings().getAttributeConverters() ) {
if ( ! attributeConverterDefinition.isAutoApply() ) {
continue;
}
log.debugf(
"Checking auto-apply AttributeConverter [%s] type [%s] for match [%s]",
attributeConverterDefinition.toString(),
attributeConverterDefinition.getEntityAttributeType().getSimpleName(),
elementClass.getSimpleName()
);
if ( areTypeMatch( attributeConverterDefinition.getEntityAttributeType(), elementClass ) ) {
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()
);
}
log.debugf(
"Checking auto-apply AttributeConverter [%s] type [%s] for match [%s]",
attributeConverterDefinition.toString(),
attributeConverterDefinition.getEntityAttributeType().getSimpleName(),
elementClass.getSimpleName()
);
if ( areTypeMatch( attributeConverterDefinition.getEntityAttributeType(), elementClass ) ) {
return attributeConverterDefinition;
}

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;
}

Expand Down
Expand Up @@ -1274,6 +1274,15 @@ else if ( anyAnn != null ) {
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;
Expand Down
Expand Up @@ -109,7 +109,7 @@ public static class Customer {
@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>();
Expand Down

0 comments on commit a1ff3a2

Please sign in to comment.