Sat Apr 17, 2010 11:17 pm
package com.codemiles.jpa;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
@Entity
@Table(name="STUDENT")
public class Student implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private long Id;
private String name;
private Date birthday;
private String gender;
@OneToMany(mappedBy="student")
private Collection<Student_Course> student_courses;
public long getId() {
return Id;
}
public void setId(long id) {
Id = id;
}
@Column(name="NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Temporal(TemporalType.DATE)
@Column(name="BIRTHDAT")
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
@Column(name="GENDER")
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public void setStudent_courses(Collection<Student_Course> student_courses) {
this.student_courses = student_courses;
}
public Collection<Student_Course> getStudent_courses() {
return student_courses;
}
}
package com.codemiles.jpa;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
@Entity
@Table(name="COURSE")
public class Course implements java.io.Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
private long Id;
private String name;
private Long credit;
private Date startDate;
private String department;
@OneToMany(mappedBy="course")
private Collection<Student_Course> student_courses;
public long getId() {
return Id;
}
public void setId( long id) {
Id = id;
}
@Column(name="NAME")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="CREDIT")
public Long getCredit() {
return credit;
}
public void setCredit(Long credit) {
this.credit = credit;
}
@Temporal(TemporalType.DATE)
@Column(name="START_DATE")
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Column(name="DEPARTMENT")
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public void setStudent_courses(Collection<Student_Course> student_courses) {
this.student_courses = student_courses;
}
public Collection<Student_Course> getStudent_courses() {
return student_courses;
}
}
package com.codemiles.jpa;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@IdClass(StudentCourseId.class)
@Table(name="STUDENT_COURSE")
public class Student_Course {
@Id
@Column(name = "STD_ID", insertable = false, updatable = false)
private long stdId;
@Id
@Column(name = "CRS_ID", insertable = false, updatable = false)
private long crsId;
@ManyToOne
@JoinColumn(name = "STD_ID")
private Student student;
@ManyToOne
@JoinColumn(name = "CRS_ID")
private Course course;
public Student_Course(){
}
public Student_Course(Student student,Course course){
this.stdId=student.getId();
this.student = student;
this.crsId=course.getId();
this.course=course;
}
public long getStdId() {
return stdId;
}
public void setStdId(long stdId) {
this.stdId = stdId;
}
public long getCrsId() {
return crsId;
}
public void setCrsId(long crsId) {
this.crsId = crsId;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
}
package com.codemiles.jpa;
import java.io.Serializable;
public class StudentCourseId implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private long stdId;
private long crsId;
public StudentCourseId() {
}
public StudentCourseId(long stdId,long crsId){
this.stdId=stdId;
this.crsId=crsId;
}
public long getStdId() {
return stdId;
}
public void setStdId(long stdId) {
this.stdId = stdId;
}
public long getCrsId() {
return crsId;
}
public void setCrsId(long crsId) {
this.crsId = crsId;
}
public boolean equals(Object o) {
return ((o instanceof StudentCourseId) &&
crsId == ((StudentCourseId)o).getCrsId() &&
stdId == ((StudentCourseId) o).getStdId());
}
public int hashCode(){
return (int) (stdId+crsId);
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.