KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > Student


1 package example;
2
3 import java.util.Collection JavaDoc;
4
5 import javax.persistence.*;
6
7 /**
8  * Implementation class for the Student bean.
9  *
10  * <code><pre>
11  * CREATE TABLE amber_query_student (
12  * id INTEGER PRIMARY KEY auto_increment,
13  * name VARCHAR(250),
14  * gender VARCHAR(1),
15  * house INTEGER
16  * );
17  * </pre></code>
18  */

19 @Entity
20 @Table(name="amber_query_student")
21 public class Student {
22   private long _id;
23   private String JavaDoc _name;
24   private String JavaDoc _gender;
25   private House _house;
26
27   public Student()
28   {
29   }
30
31   public Student(String JavaDoc name, String JavaDoc gender, House house)
32   {
33     setName(name);
34     setGender(gender);
35     setHouse(house);
36   }
37
38   /**
39    * Gets the id.
40    */

41   @Id
42   @Column(name="id")
43   @GeneratedValue
44   public long getId()
45   {
46     return _id;
47   }
48
49   /**
50    * Sets the id.
51    */

52   public void setId(long id)
53   {
54     _id = id;
55   }
56   
57   /**
58    * Returns the name of the student.
59    */

60   @Basic
61   @Column(unique=true)
62   public String JavaDoc getName()
63   {
64     return _name;
65   }
66   
67   /**
68    * Sets the name of the student.
69    */

70   public void setName(String JavaDoc name)
71   {
72     _name = name;
73   }
74
75   /**
76    * Returns the gender of the student.
77    */

78   @Basic
79   @Column(length=1)
80   public String JavaDoc getGender()
81   {
82     return _gender;
83   }
84
85   /**
86    * Sets the gender of the student.
87    */

88   public void setGender(String JavaDoc gender)
89   {
90     _gender = gender;
91   }
92
93   /**
94    * Returns the <code>House</code> that this Student belongs to.
95    */

96   @ManyToOne
97   @JoinColumn(name="house")
98   public House getHouse()
99   {
100     return _house;
101   }
102
103   /**
104    * Sets the <code>House</code> this Student belongs to.
105    */

106   public void setHouse(House house)
107   {
108     _house = house;
109   }
110 }
111
Popular Tags