We're updating the issue view to help you get more done. 

Allow AttributeConverter on attributes marked as Lob

Description

Hello!

Hibernate raises an AnnotationException when you try to bind a converter to a Lob:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 @Entity public class MyEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; @Convert(converter = MyConverter.class) @Lob private String status; @Converter public static class MyConverter implements AttributeConverter<String, Integer> { @Override public Integer convertToDatabaseColumn(String attribute) { return attribute.length(); } @Override public String convertToEntityAttribute(Integer dbData) { return ""; } } // getters and setters... }

-->

Caused by: org.hibernate.AnnotationException: AttributeConverter and explicit Type cannot be applied to same attribute [io.blep.MyEntity.status];remove @Type or specify @Convert(disableConversion = true)

After reviewing the JSR-338, I did not see any reason that avoids using converters with lobs. It says it is ok for basic attributes and not for Id, Version, relationships and Enumerated or Temporal.

Having a look to the source code, it seems that Lob attributes are considered as "explicit types" (https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java#L206) which implies they are rejected later in https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java#L425

The test case is in attachment.

Thanks!

Environment

None

Status

Assignee

Steve Ebersole

Reporter

Brice LEPORINI

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.0.0.Beta1

Priority

Major