DiscriminatorValue (Java EE 5)

Java EE API


javax.persistence Annotation Type DiscriminatorValue


@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface DiscriminatorValue

Implements: Annotation
@Target(value=TYPE)
@Retention(value=RUNTIME)

此类用于指定给定类型实体的鉴别符列的值。DiscriminatorValue 注释只能对具体的实体类指定。如果没有指定 DiscriminatorValue 注释并使用了鉴别符列,则将使用特定于提供者的函数生成表示整个类型的值。如果 DiscriminatorTypeSTRING,则鉴别符值默认为实体名称。

仅在实体类分层结构的根或应用了不同继承战略的次级分层结构中指定继承战略和鉴别符列。如果鉴别符值不是默认的,则应该为分层结构中的每个实体类指定此值。

示例:

    @Entity
    @Table(name="CUST")
    @Inheritance(strategy=SINGLE_TABLE)
    @DiscriminatorColumn(name="DISC", discriminatorType=STRING,length=20)
    @DiscriminatorValue("CUSTOMER")
    public class Customer { ... }

    @Entity
    @DiscriminatorValue("VCUSTOMER")
    public class ValuedCustomer extends Customer { ... }
 
英文文档:

Is used to specify the value of the discriminator column for entities of the given type. The DiscriminatorValue annotation can only be specified on a concrete entity class. If the DiscriminatorValue annotation is not specified and a discriminator column is used, a provider-specific function will be used to generate a value representing the entity type. If the DiscriminatorType is STRING, the discriminator value default is the entity name.

The inheritance strategy and the discriminator column are only specified in the root of an entity class hierarchy or subhierarchy in which a different inheritance strategy is applied. The discriminator value, if not defaulted, should be specified for each entity class in the hierarchy.

    Example:

    @Entity
    @Table(name="CUST")
    @Inheritance(strategy=SINGLE_TABLE)
    @DiscriminatorColumn(name="DISC", discriminatorType=STRING,length=20)
    @DiscriminatorValue("CUSTOMER")
    public class Customer { ... }

    @Entity
    @DiscriminatorValue("VCUSTOMER")
    public class ValuedCustomer extends Customer { ... }
 

Since:
Java Persistence 1.0

Required Element Summary
 String
 

Element Detail

abstract public String value()
(可选)表示行是注释的实体类型的值。

如果没有指定 DiscriminatorValue 注释并使用了鉴别符列,则将使用特定于提供者的函数生成表示整个类型的值。如果 DiscriminatorType 为 STRING,则鉴别符值默认为实体名称。

英文文档:

value

public abstract String value
(Optional) The value that indicates that the row is an entity of the annotated entity type.

If the DiscriminatorValue annotation is not specified and a discriminator column is used, a provider-specific function will be used to generate a value representing the entity type. If the DiscriminatorType is STRING, the discriminator value default is the entity name.



Submit a bug or feature

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

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

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