1.现在我有2各表,order和orderDetail
首先在映射表中要定义orderDetail
@Entity @Table(name = "T_ORDER") public class ORDER extends Base { //订单详情 @OneToOne(cascade = CascadeType.ALL, mappedBy = "order") private OrderDetail orderDetail; }
2.我要用leifjoin查询出订单所有信息的sql语句如下
hql="select new OrderDto(_o.id,_o.name,_od.describe) from Order _o left join _o.orderDetail";
这样就可以了,不用加on,会自动根据关系映射加上.
有很多表就:
from Order _o left join _o.orderDetail left join _o.orderDetail1 left join _o.orderDetail2
这样写,但order类一定要做好映射