Hibernate自关联关系
业务逻辑:
书籍的种类,本身是自关联的关系,如下图所示:
所有书籍:
历史书籍
音乐书籍
钢琴书籍
烹饪书籍
美食书籍
1. Books类的源程序
package mypack;
import java.util.Set;
import java.io.Serializable;
public class Books
implements Serializable {
/**
* 默认构造函数
*/
public Books() {
}
/** 主健id */
/** 书籍名称 */
private String name;
/** 父书籍 */
private mypack.Books parentCategory;
/** 子集合 */
private Set childCategories;
/** 完整构造函数 */
public Books(String name, mypack.Books parentCategory, Set childCategories) {
this.name = name;
this.parentCategory = parentCategory;
this.childCategories = childCategories;
}
/** 最小构造函数 */
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;