【发布时间】:2014-06-13 19:30:44
【问题描述】:
我尝试在 jpa 中转换此查询 我的 sql 原生查询。
SELECT *
FROM tripinfo ti
inner join car c on ti.carid = c.id
left join customerdetail cd on ti.customerid = cd.id
left join station s on ti.fromstxid = s.id
where ti.starttime is null or ti.stoptime is null
我的 jpa 查询
SELECT ti
FROM TripInfo ti
join ti.car
left join CustomerDetail cd on ti.customer.customerDetail.id = cd.id
left join Station st on ti.fromstxid = st.id
jpa 2.0 中似乎不存在 on 命令。
TripInfo 类
public class tripInfo{
Long id
@OneToOne
JoinColumn(name = "customerId") //can be null
Customer customer;
@OneToOne
@JoinColumn(name = "carid")
Car car;
@Column(name = "tostxid") //can be null
Long toStxId;
@Column(name = "fromstxid") //can be null
Long fromStxId;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "fromdp")
DP fromDP;
}
客户类别
public class Customer {
Long id
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "customerDetail_customerid")
CustomerDetail customerDetail;
}
DP类
public class DP {
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "stationFrom")
Station stationFrom;
}
有什么办法绕过 on 命令吗?
【问题讨论】: