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
9
10
11
12
13 @Entity
14 @Table(name="ORMREL_PHOTO")
15 public class Photo {
16 private static Logger logger = LoggerFactory.getLogger(Photo.class);
17
18 @Id @GeneratedValue @Column(name="PHOTO_ID")
19 private long id;
20 @Lob
21 private byte[] image;
22
23
24 public Photo() { logger.debug("{}: ctor()", myInstance()); }
25 public Photo(byte[] image) {
26 logger.debug(super.toString() + ": ctor() image=" + image);
27 this.image = image;
28 }
29
30 public long getId() {
31 logger.debug("{}: getId()={}", myInstance(), id);
32 return id;
33 }
34
35 public byte[] getImage() { return image; }
36 public void setImage(byte[] image) {
37 this.image = image;
38 }
39
40 private String myInstance() {
41 String s=super.toString();
42 s = s.substring(s.lastIndexOf('.')+1);
43 return s;
44 }
45
46 public String toString() {
47 long size = (image == null) ? 0 : image.length;
48 String sizeText =
49 (image == null) ? "null" : new Long(size).toString() + " bytes";
50 String s=super.toString();
51 s = s.substring(s.lastIndexOf('.')+1);
52 return myInstance() +
53 ", id=" + id +
54 ". image=" + sizeText;
55 }
56 }