hibernete中使用enum

1.新建enum

public enum RemoveFlag
{

    ENABLE(0) ,DISABLE(1);
    private int key;

    private RemoveFlag(final int key)
    {
        this.key = key;
    }

    public static RemoveFlag fromKey(int key)
    {
        for (RemoveFlag status : RemoveFlag.values())
        {
            if (key==status.getKey())
                return status;
        }
        throw new NoSuchElementException(key+"");
    }

    public int getKey()
    {
        return key;
    }
    public void setKey(int key)
    {
        this.key = key;
    }
}

2.po类

@Table(name = "index")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Index implements Serializable{

	/** * (域的意义,目的,功能) */
	private static final long serialVersionUID = -260883712964784379L;

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name = "ID", nullable = false, length = 32)
	private String Id;
	
	@Column(name = "REMOVED", nullable = true, length = 10)
	private RemoveFlag removed;
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页