休眠 CriteriaBuilder 以联接多个表
2022-09-02 01:26:16
我正在尝试使用休眠标准构建器连接4个表。
以下是分别的表格。`
@Entity
public class BuildDetails {
@Id
private long id;
@Column
private String buildNumber;
@Column
private String buildDuration;
@Column
private String projectName;
}
@Entity
public class CodeQualityDetails{
@Id
private long id;
@Column
private String codeHealth;
@ManyToOne
private BuildDetails build; //columnName=buildNum
}
@Entity
public class DeploymentDetails{
@Id
private Long id;
@Column
private String deployedEnv;
@ManyToOne
private BuildDetails build; //columnName=buildNum
}
@Entity
public class TestDetails{
@Id
private Long id;
@Column
private String testStatus;
@ManyToOne
private BuildDetails build; //columnName=buildNum
}
在这4个表中,我想为MySQL执行以下sql脚本:
SELECT b.buildNumber, b.buildDuration,
c.codeHealth, d.deployedEnv, t.testStatus
FROM BuildDetails b
INNER JOIN CodeQualityDetails c ON b.buildNumber=c.buildNum
INNER JOIN DeploymentDetails d ON b.buildNumber=d.buildNum
INNER JOIN TestDetails t ON b.buildNumber=t.buildNum
WHERE b.buildNumber='1.0.0.1' AND
b.projectName='Tera'
那么,我如何使用Hibernate CriteriaBuilder实现这一点?请帮忙...
提前致谢...