java学习

java学习

 

hibernate实体类映射父子关系

/**
 * 任务实体类
 */
@Entity
@Table(name = "t_task")
public class Task implements Serializable {

    /**
  *
  */
 private static final long serialVersionUID = 1L;
 private Long id;
    private String name;
 
    //计划开始时间
    private Date plan_startTime;
  
    private Project project;
    //父任务
    private Task parent;
 
    // 子任务
    private Set<Task> children = new HashSet<Task>();

 

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

 
    @Temporal(TemporalType.TIMESTAMP)
    public Date getPlan_startTime() {
        return plan_startTime;
    }

    public void setPlan_startTime(Date plan_startTime) {
        this.plan_startTime = plan_startTime;
    }


    @ManyToOne(optional = false, cascade = {CascadeType.REFRESH, CascadeType.MERGE})
    @JoinColumn(name = "projectId")
    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    @ManyToOne(cascade = {CascadeType.REFRESH, CascadeType.MERGE})
    @JoinColumn(name = "parentId")
    public Task getParent() {
        return parent;
    }

    public void setParent(Task parent) {
        this.parent = parent;
    }

    @OrderBy("id ASC")
    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
    public Set<Task> getChildren() {
        return children;
    }

    public void setChildren(Set<Task> children) {
        this.children = children;
    }

  
 
}

posted on 2013-11-07 14:40 杨军威 阅读(434) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜