1 package info.ejava.examples.ejb.interceptor.bo; 2 3 import java.io.Serializable; 4 5 import javax.persistence.Column; 6 import javax.persistence.Entity; 7 import javax.persistence.EnumType; 8 import javax.persistence.Enumerated; 9 import javax.persistence.FetchType; 10 import javax.persistence.GeneratedValue; 11 import javax.persistence.Id; 12 import javax.persistence.Inheritance; 13 import javax.persistence.InheritanceType; 14 import javax.persistence.JoinColumn; 15 import javax.persistence.ManyToOne; 16 import javax.validation.constraints.NotNull; 17 18 @SuppressWarnings("serial") 19 @Entity 20 @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 21 public abstract class ContactInfo implements Serializable { 22 @Id @GeneratedValue 23 @Column(name="INFO_ID") 24 private int id; 25 26 @NotNull(groups=PrePersistCheck.class) 27 @ManyToOne(fetch=FetchType.EAGER, optional=false) 28 @JoinColumn(name="CONTACT_ID", nullable=false, updatable=false) 29 private Contact contact; 30 31 @NotNull(groups={PostNormalizedCheck.class, PrePersistCheck.class}) 32 @Enumerated(EnumType.STRING) 33 @Column(name="CONTACT_ROLE", nullable=false) 34 private ContactRole role; 35 36 public abstract ContactType getContactType(); 37 38 protected ContactInfo() {} 39 public ContactInfo(Contact contact) { 40 this.contact = contact; 41 } 42 public ContactInfo(int id, Contact contact) { 43 this.id = id; 44 this.contact = contact; 45 } 46 public int getId() { return id; } 47 48 public Contact getContact() { return contact; } 49 public void setContact(Contact contact) { 50 this.contact = contact; 51 } 52 53 public ContactRole getRole() { return role; } 54 public void setRole(ContactRole role) { 55 this.role = role; 56 } 57 }