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

Warning log appears on an AttributeConverter<enum, String>

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 5.3.0.Final
    • Fix Version/s: 5.3.1
    • Component/s: hibernate-core
    • Labels:
      None
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Worked in:
    • Last commented by a user?:
      true
    • Sprint:

      Description

      When I use a AttributeConverter on my enum field in an entity, a warning log is printed about having no JavaTypeDescriptor or hashcode/equals implemented.

      Warning log

      16:50:36.689 [main] WARN  org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry - HHH000481: Encountered Java type [class FooConverter] for which we could not locate a JavaTypeDescriptor and which does not appear to implement equals and/or hashCode.  This can lead to significant performance problems when performing equality/dirty checking involving this Java type.  Consider registering a custom JavaTypeDescriptor or at least implementing equals/hashCode.
      16:50:36.710 [main] WARN  org.hibernate.type.spi.TypeConfiguration$Scope - HHH000233: Scoping types to session factory org.hibernate.internal.SessionFactoryImpl@261ddbf5 after already scoped org.hibernate.internal.SessionFactoryImpl@261ddbf5
      

      Entity.java

      @Entity(name = "Entity")
      public class Entity {
          @Id
          @Column(name = "id")
          public String id;
      
          @NotNull
          @Column(name = "foo")
          @Convert(converter = FooConverter.class)
          public Foo foo;
      }
      

      Foo.java

      public enum Foo {
          BAR_1,
          BAR_2,
      }
      

      FooConverter.class

      public class FooConverter implements AttributeConverter<Foo, String> {
          private static Map<Foo, String> typeMapping;
          static {
              typeMapping = new EnumMap<>(Foo.class);
              typeMapping.put(Foo.BAR_1, "baa_1");
              typeMapping.put(Foo.BAR_2, "baa_2");
          }
      
          @Override
          public String convertToDatabaseColumn(Foo t) {
              return typeMapping.get(t);
          }
      
          @Override
          public Foo convertToEntityAttribute(String s) {
              for (Map.Entry<typeMapping, String> entry : typeMapping.entrySet()) {
                  if (entry.getValue().equalsIgnoreCase(s)) {
                      return entry.getKey();
                  }
              }
      
              throw new IllegalArgumentException("Invalid value for enum: " + s);
          }
      }
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: