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

Warning log appears on an AttributeConverter<enum, String>

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

1 2 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

1 2 3 4 5 6 7 8 9 10 11 @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

1 2 3 4 public enum Foo { BAR_1, BAR_2, }

FooConverter.class

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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); } }

Environment

None

Status

Assignee

Chris Cranford

Reporter

Isen

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

5.2.17

Components

Affects versions

5.3.0.Final

Priority

Minor