NPersistence Reference Guide
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. If the relationship is bidirectional, the mappedBy element must be used to specify the relationship field or property of the entity that is the owner of the relationship.

The OneToMany annotation may be used within an embeddable class contained within an entity class to specify a relationship to a collection of entities. If the relationship is bidirectional, the mappedBy element must be used to specify the relationship field or property of the entity that is the owner of the relationship.

When the collection is a System.Collections.Generic.Dictionary, the cascade element and the orphanRemoval element apply to the map value.

Examples

CopyC#
Example 1: One-to-Many association using generics

// In Customer class:

[OneToMany](cascade=ALL, mappedBy="cUSTOMER")]
public Set<Order> getOrders() { 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; }


Example 3: Unidirectional One-to-Many association using a foreign key mapping

// In Customer class:

[OneToMany(orphanRemoval=true)]
[JoinColumn(name="CUST_ID")] // join column is in table for Order
public Set<Order> getOrders() {return orders;}

Namespace: NPersistence
Assembly: NPersistence (in NPersistence.dll) Version: 2.0.0.0 (2.0.0.0)

Syntax

   
 C# 
public sealed class OneToMany : Attribute

Members

         
 All Members  Constructors   Fields  
 Public

 Protected
 Instance

 Static 
 Declared

 Inherited
 XNA Framework Only 

 .NET Compact Framework Only 

 MemberDescription
OneToMany()()()()
Initializes a new instance of the OneToMany class
Cascade
(Optional) The operations that must be cascaded to the target of the association. Defaults to no operations being cascaded. When the target collection is a Dictionary, the cascade element applies to the Dictionary value.
Fetch
(Optional) Whether the association should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistence provider runtime that the associated entities must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.
MappedBy
The field that owns the relationship. Required unless the relationship is unidirectional.
OrphanRemoval
(Optional) Whether to apply the remove operation to entities that have been removed from the relationship and to cascade the remove operation to those entities.
TargetEntity
(Optional) The entity class that is the target of the association. Optional only if the collection property is defined using generics. Must be specified otherwise. Defaults to the parameterized type of the collection when defined using generics.

Inheritance Hierarchy

System..::..Object
  System..::..Attribute
    NPersistence..::..OneToMany

See Also