Chapter 9 Generating Persistent Objects for Java and JSF Pages


Mapping Many-to-many Associations

EJB 3 persistence supports both bi-directional many-to-many association mapping and unidirectional many-to-many association mapping (see the O/R Mapping chapter).

A ManyToMany annotation is generated to define a many-valued association with many-to-many multiplicity.

@ManyToMany(fetch=FetchType.EAGER)
@JoinTable(
      name="Assignment",
      joinColumns={
         @JoinColumn(name="eid", referencedColumnName="eid")
      },
      inverseJoinColumns={
         @JoinColumn(name="tid", referencedColumnName="tid")
      }
)
public java.util.Collection<Title> getTitle() { ... }

A model check is available to verify that mappings are correctly defined for many-to-many associations. Middle tables are needed for many-to-many association mapping.

 


Copyright (C) 2007. Sybase Inc. All rights reserved.