Hibernate自關(guān)聯(lián)關(guān)系
業(yè)務(wù)邏輯:
書籍的種類,本身是自關(guān)聯(lián)的關(guān)系,如下圖所示:
所有書籍:
歷史書籍
音樂書籍
鋼琴書籍
烹飪書籍
美食書籍
1. Books類的源程序
package mypack;
import java.util.Set;
import java.io.Serializable;
public class Books
implements Serializable {
/**
* 默認構(gòu)造函數(shù)
*/
public Books() {
}
/** 主健id */
/** 書籍名稱 */
private String name;
/** 父書籍 */
private mypack.Books parentCategory;
/** 子集合 */
private Set childCategories;
/** 完整構(gòu)造函數(shù) */
public Books(String name, mypack.Books parentCategory, Set childCategories) {
this.name = name;
this.parentCategory = parentCategory;
this.childCategories = childCategories;
}
/** 最小構(gòu)造函數(shù) */
public Books(Set childCategories) {
this.childCategories = childCategories;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public mypack.Books getParentCategory() {
return this.parentCategory;
}
public void setParentCategory(mypack.Books parentCategory) {
this.parentCategory = parentCategory;