|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
javax.persistence Annotation Type OneToMany
Implements:
Annotation
@Target(value={METHOD, FIELD})@Retention(value=RUNTIME)
定义带有一对多多样性的多值关联。
如果将 Collection 的元素类型指定为 generic 类型,则不必指定关联的目标实体类型;否则必须指定目标实体类。
示例 1:使用 generic 的一对多关联 在 Customer 类中: @OneToMany(cascade=ALL, mappedBy="customer") public SetgetOrders() { return orders; } 在 Order 类中: @ManyToOne @JoinColumn(name="CUST_ID", nullable=false) public Customer getCustomer() { return customer; } 示例 2:没有使用 generic 的一对多关联 在 Customer 类中: @OneToMany(targetEntity=com.acme.Order.class, cascade=ALL, mappedBy="customer") public Set getOrders() { return orders; } 在 Order 类中: @ManyToOne @JoinColumn(name="CUST_ID", nullable=false) public Customer getCustomer() { return customer; }
since |
|
Defines a many-valued association with one-to-many multiplicity.
If the collection is defined using generics to specify the element type, the associated target entity type need not be specified; otherwise the target entity class must be specified.
Example 1: One-to-Many association using generics In Customer class: @OneToMany(cascade=ALL, mappedBy="customer") public SetgetOrders() { return orders; } In Order class: @ManyToOne @JoinColumn(name="CUST_ID", nullable=false) public Customer getCustomer() { return customer; } Example 2: One-to-Many association without using generics In Customer class: @OneToMany(targetEntity=com.acme.Order.class, cascade=ALL, mappedBy="customer") public Set getOrders() { return orders; } In Order class: @ManyToOne @JoinColumn(name="CUST_ID", nullable=false) public Customer getCustomer() { return customer; }
- Since:
- Java Persistence 1.0
Optional Element Summary | |
---|---|
CascadeType[] |
cascade
(Optional) The operations that must be cascaded to the target of the association. |
FetchType |
fetch
(Optional) Whether the association should be lazily loaded or must be eagerly fetched. |
String |
mappedBy
The field that owns the relationship. |
Class |
targetEntity
(Optional) The entity class that is the target of the association. |
abstract public Class<T>
targetEntity()
(可选)作为关联目标的实体类。仅当使用 Java generic 定义了 Collection 属性时才是可选的。否则必须指定。
使用 generic 定义时,默认为参数化的 Collection 类型。
targetEntity
public abstract Class targetEntity
- (Optional) The entity class that is the target
of the association. Optional only if the collection
property is defined using Java generics.
Must be specified otherwise.
Defaults to the parameterized type of the collection when defined using generics.
- Default:
- void.class
abstract public CascadeType[]
cascade()
(可选)必须串联到关联目标的操作。
默认为不串联任何操作。
cascade
public abstract CascadeType[] cascade
- (Optional) The operations that must be cascaded to
the target of the association.
Defaults to no operations being cascaded.
- Default:
- {}
abstract public FetchType
fetch()
可选)关联应该延迟加载还是必须立即获取。EAGER
战略是必须立即获取关联实体的持久性提供者运行时的要求。LAZY
战略是持久性提供者运行时的提示。
英文文档:
fetch
public abstract FetchType fetch
- (Optional) Whether the association should be
lazily loaded or must be eagerly fetched. The
EAGER
strategy is a requirement on the persistenceprovider runtime that the associatedentities must be eagerly fetched. TheLAZY
strategy is a hint to the persistence provider runtime. - Default:
- LAZY
abstract public String
mappedBy()
拥有关系的字段。只要关系不是单向的,就需要它。
英文文档:
mappedBy
public abstract String mappedBy
- The field that owns the relationship. Required unless
the relationship is unidirectional.
- Default:
- ""
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!