Christian Koppen (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b34965...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNWEzMTA1YjRh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMT...
) HHH-13913 (
https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMT...
) AttributeConverter with autoApply is not chosen for generic typed fields (
https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMT...
)
Issue Type: Bug Affects Versions: 5.4.11 Assignee: Unassigned Attachments:
hibernate-issue-converter-autoapply-generics.zip Components: hibernate-core Created:
27/Mar/2020 10:04 AM Environment: hibernate-entitymanager:5.4.11.Final / Java 8 / Windows
/ H2 Labels: converter core regression Priority: Major Reporter: Christian Koppen (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b34965...
)
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.
(
https://hibernate.atlassian.net/browse/HHH-13913#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-13913#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100122- sha1:38c716d )