1 22 package org.jboss.ejb3.test.entitycallback; 23 24 import javax.persistence.Entity; 25 import javax.persistence.CascadeType; 26 import javax.persistence.FetchType; 27 import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; 28 import javax.persistence.Id; 29 import javax.persistence.OneToMany; 30 import javax.persistence.PostLoad; 31 import javax.persistence.PostPersist; 32 import javax.persistence.PostRemove; 33 import javax.persistence.PostUpdate; 34 import javax.persistence.PrePersist; 35 import javax.persistence.PreRemove; 36 import javax.persistence.PreUpdate; 37 import java.util.HashSet ; 38 import java.util.Set ; 39 40 44 @Entity 45 public class Customer 46 { 47 Long id; 48 String name; 49 Set <Journey> journeys = new HashSet <Journey>(); 50 51 public Customer() 52 { 53 54 } 55 56 public Customer(String name) 57 { 58 this.name = name; 59 } 60 61 @Id @GeneratedValue(strategy=GenerationType.AUTO) 62 public Long getId() 63 { 64 return id; 65 } 66 67 public void setId(Long id) 68 { 69 this.id = id; 70 } 71 72 public String getName() 73 { 74 return name; 75 } 76 77 public void setName(String name) 78 { 79 this.name = name; 80 } 81 82 @OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy="customer") 83 public Set <Journey> getJourneys() 84 { 85 return journeys; 86 } 87 88 public void setJourneys(Set <Journey> journeys) 89 { 90 this.journeys = journeys; 91 } 92 93 public void addJourney(Journey journey) 94 { 95 journeys.add(journey); 96 journey.setCustomer(this); 97 } 98 99 @PrePersist 100 public void doPreCreate() 101 { 102 System.out.println("Customer doPreCreate"); 103 CallbackCounterBean.addCallback("Customer", PrePersist.class); 104 } 105 106 @PostPersist 107 public void doPostCreate() 108 { 109 System.out.println("Customer doPostCreate"); 110 CallbackCounterBean.addCallback("Customer", PostPersist.class); 111 } 112 113 @PreRemove 114 public void doPreRemove() 115 { 116 System.out.println("Customer doPreRemove"); 117 CallbackCounterBean.addCallback("Customer", PreRemove.class); 118 } 119 120 @PostRemove 121 public void doPostRemove() 122 { 123 System.out.println("Customer doPostRemove"); 124 CallbackCounterBean.addCallback("Customer", PostRemove.class); 125 } 126 127 @PreUpdate 128 public void doPreUpdate() 129 { 130 System.out.println("Customer doPreUpdate"); 131 CallbackCounterBean.addCallback("Customer", PreUpdate.class); 132 } 133 134 @PostUpdate 135 public void doPostUpdate() 136 { 137 System.out.println("Customer doPostUpdate"); 138 CallbackCounterBean.addCallback("Customer", PostUpdate.class); 139 } 140 141 @PostLoad 142 public void doPostLoad() 143 { 144 System.out.println("Customer doPostLoad"); 145 CallbackCounterBean.addCallback("Customer", PostLoad.class); 146 } 147 } 148 | Popular Tags |