Problem: an AttributeConverter that is configured as @Converter(autoApply = true) is not used when the field is declared with a type variable (generics). Example:
interface Foo {}
@Converter(autoApply = true)
class FooConverter implements AttributeConverter<Foo, String> { ... }
@MappedSuperclass
abstract class AbstractContainer<T> { private T value; }
@Entity
class FooContainer extends AbstractContainer<Foo> { ... }
I attached a demo that demonstrates the problem. The demo runs fine using 4.3.11, and fails using 5.4.11. The problem seems to be caused by AutoApplicableConverterDescriptorStandardImpl.getAutoAppliedConverterDescriptorForAttribute(). The attribute type is resolved using the declaring class only. This is not enough. In my example, the value is resolved as Object although the subclass FooContainer knows it's a Foo. Due to the missing type info, the converter is not chosen and the type conversion fails. Since the problem did not occur in 4.3.11, I suppose this behavior is not a missing feature but a bug. |