View Javadoc
1   package ejava.examples.orm.rel.annotated;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   
6   import javax.persistence.*;
7   
8   /**
9    * This class is an example of a uni-directional ManyToMany relationship. 
10   * This class both "owns" the relationship to Media and is the only direction
11   * in which it can be navigated. There are many Media in a WantList and
12   * many WantLists associated with a Media.
13   */
14  @Entity @Table(name="ORMREL_WANTED")
15  public class WantList {
16      @Id @GeneratedValue
17      private long id;
18      @ManyToMany
19      @JoinTable(name="ORMREL_WANTED_MEDIA") //define table, but let columns use default names
20      private Collection<Media> media = new ArrayList<Media>();
21      
22      public long getId() { return id; }
23      
24      public Collection<Media> getMedia() { return media; }
25      public void setMedia(Collection<Media> media) {
26          this.media = media;
27      }
28  }