資源簡介
一個完成了hibernate的注解和配置的簡單案例;這是一個一對多【多對一】的案例,其實一對多的案例就可以解決項目中的大部分需求。因為多對多可以一般我們轉化為兩個多對一的案例;
代碼片段和文件信息
package?com.wen.model;
import?java.util.Set;
import?javax.persistence.Entity;
import?javax.persistence.GeneratedValue;
import?javax.persistence.Id;
import?javax.persistence.JoinColumn;
import?javax.persistence.ManyToOne;
import?javax.persistence.OneToMany;
import?javax.persistence.Table;
import?org.hibernate.annotations.GenericGenerator;
import?org.hibernate.annotations.LazyCollection;
import?org.hibernate.annotations.LazyCollectionOption;
/**
?*?班級實體
?*?
?*?@author?John_wen
?*?@since?2015-1-17
?*/
@Entity
@Table(name?=?“t_classroom“)
public?class?Classroom?{
/**
?*?主鍵
?*/
private?String?id;
/**
?*?班級名稱
?*/
private?String?name;
/**
?*?班級的年級代碼
?*/
private?int?grade;
/**
?*?所在的專業
?*/
private?Specialty?specialty;
/**
?*?所包含的學生
?*/
private?Set?students;
@Id
@GenericGenerator(name?=?“UUID“?strategy?=?“uuid“)
@GeneratedValue(generator?=?“UUID“)
public?String?getId()?{
return?id;
}
public?void?setId(String?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?int?getGrade()?{
return?grade;
}
public?void?setGrade(int?grade)?{
this.grade?=?grade;
}
@ManyToOne
@JoinColumn(name?=?“sid“)
public?Specialty?getSpecialty()?{
return?specialty;
}
public?void?setSpecialty(Specialty?specialty)?{
this.specialty?=?specialty;
}
@OneToMany(mappedBy?=?“classroom“)
@LazyCollection(LazyCollectionOption.EXTRA)
public?Set?getStudents()?{
return?students;
}
public?void?setStudents(Set?students)?{
this.students?=?students;
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-01-18?01:05??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1246??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件?????????396??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件?????????598??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????2248??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1862??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1556??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1032??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1630??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1193??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件????????1544??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件?????????399??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????目錄???????????0??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件??????445288??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件??????313898??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件???????75324??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件?????5272790??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件??????113371??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件???????76551??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件??????714194??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件???????57183??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件???????11558??2015-01-18?00:38??hibernate4.3.8的annotation及xm
?????文件???????27717??2015-01-18?00:38??hibernate4.3.8的annotation及xm
............此處省略66個文件信息
評論
共有 條評論