龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

Hibernate自关联关系

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
Hibernate自关联关系 业务逻辑: 书籍的种类,本身是自关联的关系,如下图所示: 所有书籍: 历史书籍 音乐书籍 钢琴书籍 烹饪书籍 美食书籍 1. Books类的源程序 Books.Java package mypack;
Hibernate自关联关系
业务逻辑:
书籍的种类,本身是自关联的关系,如下图所示:
 
所有书籍:
历史书籍
音乐书籍
           钢琴书籍
烹饪书籍
           美食书籍
 
 

1.     Books类的源程序
Books.Java
package mypack;
 
import java.util.Set;
import java.io.Serializable;
 
public class Books
    implements Serializable {
 
 /**
   * 默认构造函数
   */
 public Books() {
 }
 
 /** 主健id */
 private Long 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;

  
精彩图集

赞助商链接