`
vanadiumlin
  • 浏览: 493002 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics