Enumerated (Java EE 5)

Java EE API


javax.persistence Annotation Type Enumerated


@Target(value={METHOD,FIELD})
@Retention(value=RUNTIME)
public @interface Enumerated

Implements: Annotation
@Target(value={METHOD, FIELD})
@Retention(value=RUNTIME)

指定应该做为枚举类型保留的持久属性或字段。它可以与 Basic 注释一起使用。
示例:

   public enum EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT}

   public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}

   @Entity public class Employee {
       public EmployeeStatus getStatus() {...}
       @Enumerated(STRING)
       public SalaryRate getPayScale() {...}
       ...
   }
 
英文文档:

Specifies that a persistent property or field should be persisted as a enumerated type. It may be used in conjunction with the Basic annotation.

   Example:

   public enum EmployeeStatus {FULL_TIME, PART_TIME, CONTRACT}

   public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}

   @Entity public class Employee {
       public EmployeeStatus getStatus() {...}
       @Enumerated(STRING)
       public SalaryRate getPayScale() {...}
       ...
   }
 

Since:
Java Persistence 1.0

Optional Element Summary
 EnumType
 

abstract public EnumType value()
(可选)映射枚举类型时使用的类型。
英文文档:

value

public abstract EnumType value
(Optional) The type used in mapping an enum type.

Default:
ORDINAL


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!