auto-applied AttributeConverter isn't created by CDI
Description
Attachments
1
- 24 Oct 2019, 03:09 PM
Activity
Show:
Details
Details
Assignee
Unassigned
UnassignedReporter
Ladislav Thon
Ladislav ThonComponents
Affects versions
Priority
Created October 24, 2019 at 3:09 PM
Updated October 24, 2019 at 3:12 PM
Since JPA 2.2,
AttributeConverter
-s should support CDI injection (see also https://hibernate.atlassian.net/browse/HHH-12135#icft=HHH-12135). This doesn't seem to work when I rely on the converter being auto-applied, like this:@Converter(autoApply = true) public class MyAttributeConverter implements AttributeConverter<MyAttribute, String> { @Inject private MyUtils utils; ... } @Entity public class MyEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private MyAttribute myAttribute; ... }
This is basically Example 2: Auto-apply conversion of a basic attribute from the javadoc of
@javax.persistence.Convert
, so there should be nothing wrong with it. Yet, theutils
field inMyAttributeConverter
isnull
when the converter is invoked.However, if I apply the converter explicitly:
@Convert(converter = MyAttributeConverter.class) private MyAttribute myAttribute;
then it works just fine.
I'm no expert on JPA or CDI, but I believe auto-applied converters should support CDI as well.
As a reproducer, I'm attaching a simple Maven project which produces a WAR. I then deploy the WAR into WildFly 18.0.0.Final, which includes Hibernate ORM 5.3.12.Final (a reasonably up-to-date version).