
630
DEVELOPING
COLDFUSION 9 APPLICATIONS
Flex and AIR Integration in ColdFusion
Las
t
upda
te
d 8/5/2010
The
[JoinColumn]
tag specifies the foreign key column and all the attributes of the column tag. Do not specify
[JoinColumn]
for both the entities in the relationship. For example, in the one-to-one relationship between the
Department and Employee objects, specify
[JoinColumn]
only for one of the entities depending on the direction of
the relationship.
referencedColumnName
specifies the primary key column that it refers to.
Class
indicates the target entity, which is
Department
in this example.
The default
fetchType
value is
EAGER
. See “
Lazy loading and fetch type
” on page 631 for information on fetch types.
One-to-many relationship
Consider a one-to-many relationship where one employee belongs to many departments. You can use code like the
following to define a one-to-many mapping between the Department and Employee objects.
public class Employee
{
[Id]
var id:uint;
[OneToMany(targetEntity="Department",mappedBy="department",
fetchType="EAGER|LAZY(default)")]
var depts:ArrayCollection;
}
There is no column specified in the Employee table but refers to the field in the Department entity that points to the
Employee entity.
The default
fetchType
value is
LAZY
. See “
Lazy loading and fetch type
” on page 631 for information on fetch types
Many-to-one relationship
Consider a many-to-one relationship where many employees belong to a single department. You can use code like the
following to define a many-to-one mapping between the Department and Employee objects.
public class Employee
{
[Id]
var id:uint;
[ManyToOne(targetEntity="Department",fetchType="EAGER(default)|LAZY")]
[JoinColumn(name="deptId",referencedColumnName="DEPT_ID")]
var dept:Department;
}
The default
fetchType
value is
EAGER
. See “
Lazy loading and fetch type
” on page 631 for information on fetch types
Many-to-many relationship
Consider a many-to-many relationship where many employees belong to many departments. You can use code like
the following to define a many-to-many mapping between the Department and Employee objects.