在查询中使用枚举时无法识别的 Hibernate 类型

Jac*_*gen 7 java enums hibernate spring-boot

我有一个带有一组枚举的实体类:

@Entity
public class Something {

    public enum Type{
        FIRST_ENUM((short)1),
        SECOND_ENUM((short)2);

        private short id;

        private Type(short id) {
            this.id = id;
        }

        public short getId() {
            return id;
        }
    }

    @CollectionTable(name="table_name", joinColumns=@JoinColumn(name="something_id"))
    @Column(name="type")
    private Set<Type> types;

    ... //other props + getters and setters
}
Run Code Online (Sandbox Code Playgroud)

对于枚举,我制作了一个转换器(整个转换器包由 @EntityScan 注释加载):

@Converter(autoApply=true)
public class TypeConverter implements AttributeConverter<Type, Integer> {

    @Override
    public Integer convertToDatabaseColumn(Type st) {
        //implementation
    }

    @Override
    public Type convertToEntityAttribute(Integer i) {
        //implementation
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试在查询中使用枚举时

... AND {packagename}.Something$Type.FIRST_ENUM MEMBER OF {someobject}.something.types ...
Run Code Online (Sandbox Code Playgroud)

我偶然发现以下错误:

org.hibernate.QueryException: Unrecognized Hibernate Type for handling query constant ({package}.Something$Type.FIRST_ENUM); expecting LiteralType implementation or AttributeConverter
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我不能在查询中使用枚举?不知何故,Hibernate 似乎不知道该枚举。我不明白为什么,因为当我启动应用程序时会加载该类。