我有两个休眠对象"报告"和" ReportContent"与关键" Uuid"
有关CREATE TABLE Report(
Id BIGINT AUTO_INCREMENT PRIMARY KEY,
Uuid CHAR(32) BINARY NOT NULL UNIQUE
)
CREATE TABLE ReportContent(
Id BIGINT AUTO_INCREMENT PRIMARY KEY,
Uuid CHAR(32) BINARY NOT NULL,
Type INT NOT NULL
)
ALTER TABLE (ReportContent) ADD UNIQUE (Uuid, Type);
public class Report {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
@Column(name = "Uuid", columnDefinition = "char(32)", nullable = false, unique = true, updatable = false)
private String uuid;
@OneToMany
@JoinColumn(name = "Uuid")
private List<ReportContent> contents;
// setter and getter
}
public class ReportContent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "Id")
private long id;
@Column(name = "Uuid", nullable = false, columnDefinition = "char(32)", updatable = false)
private String uuid;
// setter and getter
}
如何做,选择Report和hibernate发送sql以获取具有条件的ReportContents Report.Uuid = ReportContent.Uuid?
答案 0 :(得分:0)
尝试类似
的内容public class Report {
// ...
@OneToMany(mappedBy = "report")
private List<ReportContent> contents;
// ...
}
并且
public class ReportContent {
// ...
@ManyToOne
@JoinColumn(name = "Uuid")
private Report report;
// ...
}