|
Hello!
Hibernate raises an AnnotationException when you try to bind a converter to a Lob:
@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 "";
}
}
}
-->
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!
|