首页 > 学院 > 开发设计 > 正文

Hibernate自关联关系

2019-11-18 11:27:26
字体:
来源:转载
供稿:网友
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;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表