AttributeOverride (Java EE 5)

Java EE API


javax.persistence Annotation Type AttributeOverride


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

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

AttributeOverride 注释用于重写 Basic(不管是显式的还是默认的)属性(或字段)或者 Id 属性(或字段)的映射。

AttributeOverride 注释可以应用于扩展了映射的超类的实体或者嵌入的字段或属性,以重写映射的超类或可嵌入类所定义的基本映射。如果没有指定 AttributeOverride 注释,则列的映射方式与原映射相同。

示例: @MappedSuperclass public class Employee { @Id protected Integer id; @Version protected Integer version; protected String address; public Integer getId() { ... } public void setId(Integer id) { ... } public String getAddress() { ... } public void setAddress(String address) { ... } } @Entity @AttributeOverride(name="address", column=@Column(name="ADDR")) public class PartTimeEmployee extends Employee { // address field mapping overridden to ADDR protected Float wage(); public Float getHourlyWage() { ... } public void setHourlyWage(Float wage) { ... } }

英文文档:

The AttributeOverride annotation is used to override the mapping of a Basic (whether explicit or default) property or field or Id property or field.

The AttributeOverride annotation may be applied to an entity that extends a mapped superclass or to an embedded field or property to override a basic mapping defined by the mapped superclass or embeddable class. If the AttributeOverride annotation is not specified, the column is mapped the same as in the original mapping.

 

Example: @MappedSuperclass public class Employee { @Id protected Integer id; @Version protected Integer version; protected String address; public Integer getId() { ... } public void setId(Integer id) { ... } public String getAddress() { ... } public void setAddress(String address) { ... } } @Entity @AttributeOverride(name="address", column=@Column(name="ADDR")) public class PartTimeEmployee extends Employee { // address field mapping overridden to ADDR protected Float wage(); public Float getHourlyWage() { ... } public void setHourlyWage(Float wage) { ... } }

Since:
Java Persistence 1.0
See Also:
Embedded, Embeddable, MappedSuperclass

Required Element Summary
 Column
 String
 

Element Detail

abstract public String name()
(必需)如果使用的是基于属性的访问,则此为映射被重写的属性名称;如果使用的是基于字段的访问,则为字段名称。
英文文档:

name

public abstract String name
(Required) The name of the property whose mapping is being overridden if property-based access is being used, or the name of the field if field-based access is used.


abstract public Column column()
(必需)映射到持久属性的列。映射类型与可嵌入类或映射超类中定义的类型保持一致。
英文文档:

column

public abstract Column column
(Required) The column that is being mapped to the persistent attribute. The mapping type will remain the same as is defined in the embeddable class or mapped superclass.



Submit a bug or feature

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

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

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