1 package ejava.examples.orm.rel.annotated;
2
3 import javax.persistence.*;
4
5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
7
8 import ejava.examples.orm.rel.MediaCopyPK;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 @Entity @Table(name="ORMREL_MEDIACOPY")
43 @IdClass(MediaCopyPK.class)
44 public class MediaCopy {
45 private static final Logger log = LoggerFactory.getLogger(MediaCopy.class);
46 @Id
47 private int copyNo;
48 @Id
49 private long mediaId;
50 @ManyToOne
51 @JoinColumn(name="MEDIACOPY_MID",
52 insertable=false, updatable=false)
53 private Media media;
54
55 protected MediaCopy() { log.debug(super.toString() + ": ctor()"); }
56 public MediaCopy(Media media, int copyNo) {
57 log.debug(super.toString() + ": ctor() mediaId="
58 + media.getId() + ", copyNo=" + copyNo);
59 setMedia(media);
60 setMediaId(media.getId());
61 setCopyNo(copyNo);
62 }
63
64 public int getCopyNo() { return copyNo; }
65 private void setCopyNo(int copyNo) { this.copyNo = copyNo; }
66
67 public long getMediaId() { return mediaId; }
68 private void setMediaId(long mediaId) { this.mediaId = mediaId; }
69
70 public Media getMedia() { return media; }
71 private void setMedia(Media media) { this.media = media; }
72
73 private String myInstance() {
74 String s=super.toString();
75 s = s.substring(s.lastIndexOf('.')+1);
76 return s;
77 }
78
79 public String toString() {
80 return myInstance() +
81 ", mediaId=" + mediaId +
82 ", copyNo=" + copyNo +
83 ", media=" + media;
84 }
85 }