oneToMany,ManyToOne双向关联


package com.xuguang.ext.xgerp.comm.workshop.bean;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.FetchType;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
* 工作点
* @author ztw
*
*/
@Entity
@Table(name="comm_workshop")
public class WorkShop implements Serializable {

/**
*
*/
private static final long serialVersionUID = -7502127838260795796L;
/**
* 关键字
*/
private String workshopPK;
/**
* 编号
*/
private String workshopNo;
/**
* 名称
*/
private String workshopName;
/**
* 类型
*/
private String workshopType;
/**
* 父
*/
private WorkShop father;
/**
* 子
*/
private List<WorkShop> sons;
@Id
public String getWorkshopPK() {
return workshopPK;
}
public void setWorkshopPK(String workshopPK) {
this.workshopPK = workshopPK;
}
public String getWorkshopNo() {
return workshopNo;
}
public void setWorkshopNo(String workshopNo) {
this.workshopNo = workshopNo;
}
public String getWorkshopName() {
return workshopName;
}
public void setWorkshopName(String workshopName) {
this.workshopName = workshopName;
}
public String getWorkshopType() {
return workshopType;
}
public void setWorkshopType(String workshopType) {
this.workshopType = workshopType;
}

@ManyToOne(targetEntity=WorkShop.class)
@JoinColumn(name="fatherPK")
@NotFound(action=NotFoundAction.IGNORE)
public WorkShop getFather() {
return father;
}
public void setFather(WorkShop father) {
this.father = father;
}

@OneToMany(mappedBy="father",fetch=FetchType.EAGER)
@OrderBy("workshopName")
public List<WorkShop> getSons() {
return sons;
}
public void setSons(List<WorkShop> sons) {
this.sons = sons;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值