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
10
11
12
13 @Entity @Table(name="ORMMAP_MANYMANY_INVENTITY")
14 public class ManyManyInverseEntity {
15 @Id
16 private String name;
17
18 @ManyToMany(mappedBy="ownedInverseEntities")
19 @MapKey(name="name")
20 private Map<String, ManyManyOwningEntity> ownedByEntities = new HashMap<String, ManyManyOwningEntity>();
21
22
23 protected ManyManyInverseEntity() {}
24 public ManyManyInverseEntity(String name) { this.name = name; }
25
26 public String getName() { return name; }
27
28 public Map<String, ManyManyOwningEntity> getOwnedByEntities() { return ownedByEntities; }
29 public void setOwnedByEntities(Map<String, ManyManyOwningEntity> ownedByEntities) {
30 this.ownedByEntities = ownedByEntities;
31 }
32
33 public String toString() {
34 StringBuilder text = new StringBuilder();
35
36 text.append(getClass().getName());
37 text.append(", name=" + name);
38 if (ownedByEntities != null) {
39 text.append(", ownedByEntities=(" + ownedByEntities.size() + ")={");
40 for (String key : ownedByEntities.keySet()) {
41 text.append(ownedByEntities.get(key).getName() + ", ");
42 }
43 text.append("}");
44 }
45 return text.toString();
46 }
47 }