我的表结构如下
req_id parent_req_id
1 null
2 1
3 1
4 1
5 2
6 2
7 3
我需要编写一个HQL查询,如果输入为1,我需要检索1,2,3,4,5,6,7。由于2,3,4是1和5,6,7的直系子女,因此是其孙子。请在下面找到hiberate的bean结构
@Entity
@Table(name = "requirements")
public class RequirementsDTO implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GenericGenerator(name="generator", strategy="increment")
@GeneratedValue(generator="generator")
@Basic(optional = false)
@Column(name = "req_id")
private Integer reqId;
@Column(name = "req_name")
private String reqName;
@Column(name = "req_desc")
private String reqDesc;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "reqId")
private List<RequirementActorsDTO> requirementActorsDTOList;
@OneToMany(mappedBy = "parentReqId")
private List<RequirementsDTO> requirementsDTOList;
@JoinColumn(name = "parent_req_id", referencedColumnName = "req_id")
@ManyToOne
private RequirementsDTO parentReqId;
//getters and setters
}