我正在开发一个需要使用以下查询的应用程序 在休眠状态。
select
requestorc0_.LASTUPDTED as LASTUPDTED
requestcom1_.START_DATE as START_DATE
from
REQUESTOR_CONTACT requestorc0_
left outer join
REQUESTOR requestcom1_ on requestorc0_.REQUESTOR_ID=requestcom1_.REQUESTOR_ID
inner join REVIEW c1 on (requestorc0_.requestor_contact_id=c1.requestor_id OR requestorc0_.requestor_id=c1.requestor_id)
我需要将此查询转换为休眠bean。我正在尝试使用连接公式,但无法找出正确的方法。
@Entity
@Table(name = "REVIEW")
public class RequestReview implements Serializable {
@Id
@Column(name = "RECORD_ID")
private Integer recordId
@Column(name = "REQUESTOR_ID")
private Integer requestorId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumnOrFormula(formula = @JoinFormula(
value = "(SELECT r FROM RequestorContact r WHERE r.requestorContactId = requestorId OR r.requestorId = requestorId LIMIT 1)",
referencedColumnName = "REQUESTOR_CONTACT_ID"))
private RequestorContact requestorContact;
}
@Entity
@Table(name = "REQUESTOR_CONTACT")
public class RequestorContact implements Serializable {
@ID
@Column(name = "REQUESTOR_CONTACT_ID")
private Integer requestorContactId;
@Column(name = "REQUESTOR_ID")
private Integer requestorId;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "REQUESTOR_ID", insertable = false, updatable = false)
private RequestCompany requestCompany;
}
@Entity
@Table(name = "REQUESTOR")
public class RequestCompany implements Serializable {
@Id
@Column(name = "REQUESTOR_ID", unique = true, nullable = false)
private Integer requestorId;
}
我无法根据上面的预期查询创建正确的公式。有人可以帮我吗?