View Javadoc
1   package ejava.examples.orm.map.annotated;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import javax.persistence.*;
7   
8   /**
9    * This class represents the owning side of a Many-to-Many, bi-directional and 
10   * uni-directional relationship. The ManyManyEntity
11   * relationship is uni-directional from this entity. The ManyManyInverseEntity
12   * relationship is bi-directional, but owned by this entity.
13   */
14  @Entity @Table(name="ORMMAP_MANYMANY_OWNENTITY")
15  public class ManyManyOwningEntity {
16      @Id
17      private String name;
18  
19      @ManyToMany
20      @MapKey(name="name")
21      private Map<String, ManyManyEntity> ownedEntities =
22              new HashMap<String, ManyManyEntity>();
23  
24      @ManyToMany
25      @MapKey(name="name")
26      private Map<String, ManyManyInverseEntity> ownedInverseEntities =
27              new HashMap<String, ManyManyInverseEntity>();	
28      
29      protected ManyManyOwningEntity() {}
30      public ManyManyOwningEntity(String name) {
31          this.name = name;
32      }
33      
34      public String getName() { return name; }
35      
36      public Map<String, ManyManyEntity> getOwnedEntities() { return ownedEntities; }
37      public void setOwnedEntities(Map<String, ManyManyEntity> ownedEntities) {
38          this.ownedEntities = ownedEntities;
39      }
40      
41      public Map<String, ManyManyInverseEntity> getOwnedInverseEntities() { return ownedInverseEntities; }
42      public void setOwnedInverseEntities(
43                  Map<String, ManyManyInverseEntity> ownedInverseEntities) {
44          this.ownedInverseEntities = ownedInverseEntities;
45      }
46      
47      public String toString() {
48          StringBuilder text = new StringBuilder();
49          text.append(getClass().getName());
50          text.append(", name=" + name);
51          if (ownedEntities != null) {
52              text.append(", ownedEntities=" + ownedEntities);
53          }
54          if (ownedInverseEntities != null) {
55              text.append(", ownedInverseEntities=" + ownedInverseEntities);
56          }
57          
58          return text.toString();
59      }
60  }