KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > onetomany > Troop


1 //$Id: Troop.java,v 1.6 2005/07/20 00:18:06 epbernard Exp $
2
package org.hibernate.test.annotations.onetomany;
3
4 import java.util.HashSet JavaDoc;
5 import java.util.Set JavaDoc;
6 import javax.persistence.CascadeType;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratorType;
9 import javax.persistence.Id;
10 import javax.persistence.OneToMany;
11 import javax.persistence.FetchType;
12
13 import org.hibernate.annotations.OnDelete;
14 import org.hibernate.annotations.OnDeleteAction;
15 import org.hibernate.annotations.OrderBy;
16
17 /**
18  * Shows a default one to many
19  * @author Emmanuel Bernard
20  */

21 @Entity
22 public class Troop {
23     private Integer JavaDoc id;
24     private String JavaDoc name;
25     private Set JavaDoc<Soldier> soldiers;
26
27     @OneToMany(mappedBy="troop", cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
28     @OrderBy(clause="name desc")
29     @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
30     @OnDelete(action=OnDeleteAction.CASCADE)
31     public Set JavaDoc<Soldier> getSoldiers() {
32         return soldiers;
33     }
34
35     public void setSoldiers(Set JavaDoc<Soldier> soldiers) {
36         this.soldiers = soldiers;
37     }
38
39     @Id(generate = GeneratorType.AUTO)
40     public Integer JavaDoc getId() {
41         return id;
42     }
43
44     public void setId(Integer JavaDoc id) {
45         this.id = id;
46     }
47
48     public String JavaDoc getName() {
49         return name;
50     }
51
52     public void setName(String JavaDoc name) {
53         this.name = name;
54     }
55
56     public void addSoldier(Soldier s) {
57         if (soldiers == null) soldiers = new HashSet JavaDoc<Soldier>();
58         soldiers.add(s);
59         s.setTroop(this);
60     }
61
62 }
63
Popular Tags