[英]JPA Query get enum value
I've been going through many threads but none of them included an answer for my problem.我经历了很多线程,但没有一个包含我的问题的答案。
I got a single enum class:我有一个枚举类:
public enum EActivationFunction {
FKT_RELU("ReLU"),
FKT_SIGMOID("Sigmoid"),
FKT_TANH("Tanh"),
FKT_LINEAR("Linear");
@Getter private String name;
EActivationFunction(final String name) {
this.name = name;
}
}
That is used in the normal ActivationFunction class:用于普通 ActivationFunction 类:
@Enumerated(EnumType.STRING)
@Column(length = 20)
private EActivationFunction type;
My query shortened:我的查询缩短了:
@Query(
"SELECT f FROM MlpConfig f WHERE f.user = :user AND com.project.customMlp.domain.enumeration.EActivationFunction like %:searchQuery%")
So I tried full qualified name which does not work at all.所以我尝试了完全无效的完全限定名称。 When I query like this it works but not the name is used but the enum itself so FKT_RELU instead of relu:
当我这样查询时,它可以工作,但没有使用名称,而是使用枚举本身,因此 FKT_RELU 而不是 relu:
lower(f.activationFunction.type)
ActivationFunction is another foreign entity of the main entity MlpConfig. ActivationFunction 是主实体 MlpConfig 的另一个外部实体。 How can I get the name?
我怎样才能得到这个名字? So normally:
所以通常:
f.activationFunction.type.name
In JPA, an Enum value can be mapped to its enum name or ordinal value.在 JPA 中,一个 Enum 值可以映射到它的枚举名称或序号值。 So the user-defined member variable of the enum type is invisible to JPA.
所以enum类型的用户自定义成员变量对JPA是不可见的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.