有建模爲三個實體三個表:JPA 3路連接註釋
@Entity
@Table(name="event")
public class Event {
public Long datetime;
public String name;
public Long processId;
}
@Entity
@Table(name="process")
public class Process {
public Long Id;
public Long sequence;
public Name name;
}
@Entity
@Table(name="operation")
public class Operation {
public Long Id;
public Long datetime;
public Long sequence;
}
流程操作序列的任何獨特的單記錄由具有3路連接限制的SQL獲得:
SELECT *
FROM event e, process p, operation q
WHERE e.processId = p.id
AND e.datetime = q.datetime
AND p.sequence = q.sequence
爲了實現在JPA,我必須做出操作的列表, 這將是明確的範圍縮小到救援人員到場的JQPL平等p.sequence一個記錄= q.sequence
@Entity
@Table(name="event")
public class Event {
public Long datetime;
public String name;
public Long processId;
@OneToOne
@JoinColumn(
name = "processId", referencedColumnName="id",
insertable=false, updatable=false)
private Process process;
@OneToMany
@JoinColumn(
name = "datetime", referencedColumnName="datetime",
insertable=false, updatable=false)
private List<Operation> operations;
}
凡JPQL指定傳遞第三個加入約束:
SELECT e FROM Event e
INNER JOIN FETCH e.process p
INNER JOIN FETCH e.operations q
WHERE p.sequence = q.sequence
不過,我想所有的三個約束的實體POJO內進行建模。難道不應該有辦法單獨使用JPA註釋來進行三向連接嗎?如下面的實體的僞代碼說明:在JPQL
SELECT e FROM Event e
INNER JOIN FETCH e.process p
INNER JOIN FETCH e.operations q
@Entity
@Table(name="event")
public class Event {
public Long datetime;
public String name;
public Long processId;
@OneToOne
@JoinColumn(
name = "processId", referencedColumnName="id",
insertable=false, updatable=false)
private Process process;
@OneToOne
@JoinColumn(
name = "datetime", referencedColumnName="datetime",
insertable=false, updatable=false)
@JoinColumn(
name = "process.sequence", referencedColumnName="sequence",
insertable=false, updatable=false)
private Operation operations;
}
因此,它沒有必要指定傳遞聯接約束如何使用JPA註釋連接模型的傳遞?
BTW,我已經離開了JAXB註釋。事件必須絕對是XML根標籤。因此,使用事件POJO對實體進行建模。 Event實體直接用作XML DTO和JAXB。也就是說,你不應該建議我使用另一個POJO作爲根。 –
我不是100%確定你的問題是什麼......如果你指定了連接的ON子句,它不能解決你的問題嗎? – slambeth