Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 枚举与查找表_Java_Ebean - Fatal编程技术网

Java 枚举与查找表

Java 枚举与查找表,java,ebean,Java,Ebean,我正在使用Ebean在Java中实现一个解决方案,在使用enum还是简单地查找表之间进行选择时遇到了一些问题 我有一张桌子“牙齿”。牙齿可以是“暂时的”或“永久的” 我可以创建一个简单的枚举: @EnumMapping(nameValuePairs = "TEMPORARY=T, PERMANENT=P") public enum DentitionType { TEMPORARY, PERMANENT; } 但是,如果我要执行直接SQL查询,我必须转换“T”和“p”,因此解决方案是使用如下查

我正在使用Ebean在Java中实现一个解决方案,在使用enum还是简单地查找表之间进行选择时遇到了一些问题

我有一张桌子“牙齿”。牙齿可以是“暂时的”或“永久的”

我可以创建一个简单的枚举:

@EnumMapping(nameValuePairs = "TEMPORARY=T, PERMANENT=P")
public enum DentitionType { TEMPORARY, PERMANENT; }
但是,如果我要执行直接SQL查询,我必须转换“T”和“p”,因此解决方案是使用如下查找表:

@Entity
public class DentitionType {

    @Column(length = 15)
    public String name;

    private static DentitionType permanent;

    public boolean isTemporary() {
        return !this.equals(getPermanent());
    }

    public boolean isPermanent() {
        return this.equals(getPermanent());
    }

    public static DentitionType getPermanent() {
        if (permanent == null) {
            permanent = DentitionType.FIND.byId(2L);
        }

        return permanent;
    }
}
这感觉像是硬编码的,对于较大的表,需要很多isSomething函数

有更好的解决办法吗?提前感谢。

为什么不使用

public enum DentitionType {
    TEMPORARY('T'), PERMANENT('P');
    private char value;
    private Currency(char value) {
        this.value = value;
    }
    public static DentitionType Get(final char value){
        for (DentitionType type : DentitionType.values())
        if (type.name == name)
            return type;
        return null;
    }
};

我正试图找出指定引用/查找表的最佳方法。我所有的查找都来自数据库,这样我就可以保持引用的完整性。你最后做了什么?@dotnetter我用了查找表。但我仍然发现硬编码的。。。