Uploaded image for project: 'Hibernate ORM'
  1. HHH-9615

Allow AttributeConverter on attributes marked as Lob

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.0.0.Beta1
    • Fix Version/s: 5.1.0
    • Component/s: hibernate-core
    • Labels:
    • Last commented by a user?:
      true
    • Sprint:

      Description

      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 "";
              }
          }
      
      // 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!

        Attachments

          Issue links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 2.8h
                  2.8h