[hibernate-issues] [JIRA] (HHH-13913) AttributeConverter with autoApply is not chosen for generic typed fields

Christian Koppen (JIRA) jira at hibernate.atlassian.net
Fri Mar 27 13:04:24 EDT 2020


Christian Koppen ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5b349655349a91633c1ba9bc ) *created* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 ) / Bug ( https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 ) HHH-13913 ( https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 ) AttributeConverter with autoApply is not chosen for generic typed fields ( https://hibernate.atlassian.net/browse/HHH-13913?atlOrigin=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 )

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=5b349655349a91633c1ba9bc )

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=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13913#add-comment?atlOrigin=eyJpIjoiNWEzMTA1YjRhNzQ4NDZlMWE4YTQwZDk0MGE5ZGIyYjAiLCJwIjoiaiJ9 )

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.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100122- sha1:38c716d )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200327/71152168/attachment.html 


More information about the hibernate-issues mailing list