diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/CharacterColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/CharacterColumnTest.java new file mode 100644 index 0000000000..c4c6952aae --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/CharacterColumnTest.java @@ -0,0 +1,72 @@ +package org.hibernate.orm.test.query.hql; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Converter; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SessionFactory +@DomainModel(annotatedClasses = { CharacterColumnTest.MyEntity.class }) +public class CharacterColumnTest { + + @Test + public void queryTest(SessionFactoryScope scope) { + scope.inSession( + session -> { + final var list = session.createQuery( "from MyEntity where status='A'", MyEntity.class ) + .getResultList(); + assertTrue( list.isEmpty() ); + } + ); + } + + public static enum Status { + OK( 'O' ), + ERROR( 'E' ); + + private final char value; + + Status(char value) { + this.value = value; + } + + public char value() { + return value; + } + } + + @Converter(autoApply = true) + public static class StatusAttributeConverter implements AttributeConverter { + + @Override + public Character convertToDatabaseColumn(final Status attribute) { + return attribute == null ? null : attribute.value(); + } + + @Override + public Status convertToEntityAttribute(final Character dbData) { + return dbData == null ? null : dbData == 'O' ? Status.OK : Status.ERROR; + } + } + + @Entity(name = "MyEntity") + public static class MyEntity { + @Id + @GeneratedValue + public Long id; + + @Column(length = 1) + @Convert(converter = StatusAttributeConverter.class) + public Status status; + } +}