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
10
11
12
13
14
15 @Entity @Table(name="ORMREL_INVENTORY")
16 public class Inventory {
17 @Id @GeneratedValue
18 private long id;
19 private String name;
20
21 @OneToMany(cascade={CascadeType.ALL})
22 @JoinTable(name="ORMREL_INVENTORY_MEDIA")
23
24 private Collection<Media> media = new ArrayList<Media>();
25
26 public Inventory() {}
27 public Inventory(long id) { this.id = id; }
28
29 public long getId() { return id; }
30
31 public Collection<Media> getMedia() { return media; }
32 public void setMedia(Collection<Media> media) {
33 this.media = media;
34 }
35
36 public String getName() { return name; }
37 public void setName(String name) {
38 this.name = name;
39 }
40
41 public String toString() {
42 StringBuilder text = new StringBuilder(super.toString());
43 text.append(", id=" + id);
44 text.append(", name=" + name);
45 text.append(", media(" + media.size() + ")={");
46 for(Media m: media) {
47 text.append(m.getId() + ",");
48 }
49 text.append("}");
50 return text.toString();
51 }
52 }