jpa 多表关联查询及SQL语句

@Entity
@Table(name = "goods")
public class Goods {
private String id;
private String name;
private String description;
private Double price;
private String yuanjia;
private Date createDate;
private Date modifyDate;

..........................................

@NamedQueries( { @NamedQuery(name = "getUserOrder", query = "from OrderDetail o where o.user.id=? order by createDate desc") })
@Entity
public class OrderDetail {
private String id;
   private List<OrderDetailItem> orderDetailItem = new ArrayList<OrderDetailItem>();

..............................................

@Entity
@Table(name = "orderdetailitem")
public class OrderDetailItem {
private static final long serialVersionUID = 1L;
private String id;
private Goods goods = new Goods();
private Integer num;
private OrderDetail orderDetail;

///

public class GeneralVO2{
private String id;
private String name;
private Double price;
private int num;

public GeneralVO2(String id, String name, Double price, int num) {
   super();
   this.id = id;
   this.name = name;
   this.price = price;
   this.num = num;
}

public List<OrderDetailItem> getOrderDetailItem(OrderDetail orderDetail) {
   //查询语句一
   String JPQL = "select new org.ncist.evaaass.qsl.vo.GeneralVO2 (o.orderDetail.id,o.goods.name,o.goods.price,o.num) "
       + " from "
       + OrderDetailItem.class.getSimpleName()
     + " o where o.orderDetail.id ='"
     + orderDetail.getId() + "'";
   //查询语句二
   /*String JPQL = "select o.id,o.orderDetailItem.goods.name,o.orderDetailItem.goods.price,o.orderDetailItem.num"
    + " from "
    + OrderDetail.class.getSimpleName()
    + " o where o.id='"
    + orderDetail.getId() + "'";*/
   List list=dao.getByJQL(JPQL, 0, 400);
   return list;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值