|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
Use a many-to-many mapping to represent the relationships between a collection of source objects and a collection of target objects. This mapping requires the creation of an intermediate table (the association table) for managing the associations between the source and target records.
You define a many-to-many mapping at one of the property (getter or setter method) or field level of your entity.
For more information, see "Understanding Many-to-Many Mapping" in the Oracle TopLink Developer's Guide.
|
Note: For an EJB 3.0 basic mapping code example, see:http://www.oracle.com/technology/tech/java/oc4j/ejb3/howtos-ejb3/howtoejb30mappingannotations/doc/how-to-ejb30-mapping-annotations.html#manytomany.
|
Example 7-19 shows how to use the @ManyToMany annotation to specify a many-to-many mapping for field projects and how to use the @AssociationTable annotation to specify an association table.
Example 7-19 @ManyToMany
@ManyToMany(cascade=PERSIST)
@AssociationTable(
table=@Table(name="EJB_PROJ_EMP"),
joinColumns=@JoinColumn(name="EMP_ID", referencedColumnName="EMP_ID"),
inverseJoinColumns=@JoinColumn(name="PROJ_ID", referencedColumnName="PROJ_ID")
)
public Collection getProjects()
{
return projects;
}