休眠查询得到child
Hibernate query to get child
我想获取所有 child 用户。
我有两列 parent 和 child
在parenttable--
id pname pid(fk of parent)
1 A
2 B 1
3 C 2
在childtable---
id cname cid(fk of child) pid(fk of parent)
1 AA 1
2 BA 1 2
3 BC 2 2
4 CA 3 3
5 CC 4 3
如果parent一个--
获取全部 child
if parent B--
获得 BA、BB、CA、CC
if parent C--
获取 CA,CC
我得到了答案,但它不是单一查询.. 任何休眠单一查询都可以做到这一点
更新......
public class Parent implements PersistEntity{
@Id
@Column(name = "parent_id")
@SequenceGenerator(name="OH",sequenceName="OH", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OH")
private Long parentid;
@Column(name = "parent_name")
private String parentName;
@ManyToOne
@JoinColumn(name = "fk_parent_id")
private Parent fkparentId;
}
public class Child implements PersistEntity{
@Id
@Column(name = "child_id")
@SequenceGenerator(name="OP",sequenceName="OP",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OP")
private Long childId;
@Column(name = "child_name")
private String childName;
@ManyToOne
@JoinColumn(name = "fk_child_id")
private Child fkchildId;
@ManyToOne
@JoinColumn(name = "fk_office_hierarchy_parent")
private Parent fkparentId;
}
我在 jpa 中使用递归查询解决了
我想获取所有 child 用户。 我有两列 parent 和 child
在parenttable--
id pname pid(fk of parent)
1 A
2 B 1
3 C 2
在childtable---
id cname cid(fk of child) pid(fk of parent)
1 AA 1
2 BA 1 2
3 BC 2 2
4 CA 3 3
5 CC 4 3
如果parent一个-- 获取全部 child
if parent B-- 获得 BA、BB、CA、CC
if parent C-- 获取 CA,CC
我得到了答案,但它不是单一查询.. 任何休眠单一查询都可以做到这一点
更新......
public class Parent implements PersistEntity{
@Id
@Column(name = "parent_id")
@SequenceGenerator(name="OH",sequenceName="OH", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OH")
private Long parentid;
@Column(name = "parent_name")
private String parentName;
@ManyToOne
@JoinColumn(name = "fk_parent_id")
private Parent fkparentId;
}
public class Child implements PersistEntity{
@Id
@Column(name = "child_id")
@SequenceGenerator(name="OP",sequenceName="OP",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="OP")
private Long childId;
@Column(name = "child_name")
private String childName;
@ManyToOne
@JoinColumn(name = "fk_child_id")
private Child fkchildId;
@ManyToOne
@JoinColumn(name = "fk_office_hierarchy_parent")
private Parent fkparentId;
}
我在 jpa 中使用递归查询解决了