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
14
15
16 @Entity @Table(name="ORMMAP_ONEMANY_OWNPARENT")
17 public class OneManyOwningParent {
18 @Id @Column(name="ID")
19 private String name;
20
21 @ManyToMany
22 @MapKey(name="name")
23 @JoinTable(name="ORMMAP_OWNPARENT_INVCHILD_LINK",
24 joinColumns=@JoinColumn(name="PARENT_ID"),
25 inverseJoinColumns=@JoinColumn(name="CHILD_ID"))
26 private Map<String, OneManyChild> ownedChildren =
27 new HashMap<String, OneManyChild>();
28
29 protected OneManyOwningParent() {}
30 public OneManyOwningParent(String name) { this.name = name; }
31
32 public String getName() { return name; }
33 public void setName(String name) {
34 this.name = name;
35 }
36
37 public Map<String, OneManyChild> getOwnedChildren() { return ownedChildren; }
38 public void setOwnedChildren(Map<String, OneManyChild> ownedChildren) {
39 this.ownedChildren = ownedChildren;
40 }
41
42 public String toString() {
43 StringBuilder text = new StringBuilder();
44 text.append(getClass().getName());
45 text.append(", name=" + name);
46 if (ownedChildren != null) {
47 text.append(", ownedChildren=" + ownedChildren);
48 }
49 return text.toString();
50 }
51 }