資源簡(jiǎn)介
一個(gè)完成了hibernate的注解和配置的簡(jiǎn)單案例;這是一個(gè)一對(duì)多【多對(duì)一】的案例,其實(shí)一對(duì)多的案例就可以解決項(xiàng)目中的大部分需求。因?yàn)槎鄬?duì)多可以一般我們轉(zhuǎn)化為兩個(gè)多對(duì)一的案例;
代碼片段和文件信息
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;
/**
?*?班級(jí)實(shí)體
?*?
?*?@author?John_wen
?*?@since?2015-1-17
?*/
@Entity
@Table(name?=?“t_classroom“)
public?class?Classroom?{
/**
?*?主鍵
?*/
private?String?id;
/**
?*?班級(jí)名稱
?*/
private?String?name;
/**
?*?班級(jí)的年級(jí)代碼
?*/
private?int?grade;
/**
?*?所在的專業(yè)
?*/
private?Specialty?specialty;
/**
?*?所包含的學(xué)生
?*/
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;
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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個(gè)文件信息
評(píng)論
共有 條評(píng)論