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
14 @Entity
15 @Table(name="ORMREL_PERSON")
16 public class Person {
17 private static Logger logger = LoggerFactory.getLogger(Person.class);
18 @Id @GeneratedValue @Column(name="PERSON_ID")
19 private long id;
20 private String firstName;
21 private String lastName;
22 private String phone;
23
24 @OneToOne(cascade={
25 CascadeType.ALL},
26 fetch=FetchType.LAZY)
27 @JoinColumn(name="PERSON_PHOTO")
28 private Photo photo;
29
30 public Person() { if (logger.isDebugEnabled()) { logger.debug("{}, ctor()", myInstance()); } }
31
32 public long getId() {
33 return id;
34 }
35
36 public String getFirstName() { return firstName; }
37 public void setFirstName(String firstName) {
38 this.firstName = firstName;
39 }
40
41 public String getLastName() { return lastName; }
42 public void setLastName(String lastName) {
43 this.lastName = lastName;
44 }
45
46 public String getPhone() { return phone; }
47 public void setPhone(String phone) {
48 this.phone = phone;
49 }
50
51 public Photo getPhoto() { return photo; }
52 public void setPhoto(Photo photo) {
53 this.photo = photo;
54 }
55
56 private String myInstance() {
57 String s=super.toString();
58 s = s.substring(s.lastIndexOf('.')+1);
59 return s;
60 }
61
62 public String toString() {
63 return myInstance() +
64 ", id=" + id +
65 ", name=" + firstName + " " + lastName +
66 ", phone=" + phone +
67 ", photo=" + photo;
68 }
69
70 }