问题描述
哪位大哥帮小弟看看,小弟感激不尽。对应的类有Goods (商品) private String id;//编号 private String name;//名字 private Double price;//价格--------------------------------------OrderDetail//订单 private String id;//订单号 private List<OrderDetailItem> orderDetailItem = new ArrayList<OrderDetailItem>();——-------------------------------OrderDetailItem//订单明细 private String id;//ID private Goods goods = new Goods(); private Integer num;//数量怎么写HQL语句把三个表关联在一起,根据订单的ID查询出对应该的商品名字、价格、数量?我也写了总是报错如下:select new org.ncist.evaaass.qsl.domain.shop.Goods(o.id,o.name,o.price), new org.ncist.evaaass.qsl.domain.shop.OrderDetailItem(p.num) from org.ncist.evaaass.qsl.domain.shop.OrderDetail e, org.ncist.evaaass.qsl.domain.shop.OrderDetailItem p, org.ncist.evaaass.qsl.domain.shop.Goods o where o.id = p.id and p.id = e.id and e.id='402880e82c054f2c012c05749f44000e'
解决方案
OrderDetailItem缺少了OrderDetail的多对一,需要补上,然后select model.goods model from OrderDetailItem as model where model.这里填OrderDetail多对一的变量名.id = '402880e82c054f2c012c05749f44000e'
解决方案二:
学习啦!up!!
解决方案三:
好久没玩过hibernamte了。你的这些pojo是eclipse自动生成的吗?如果不是的话,你就需要在xml文件中对这些表关联。private Set<OrderDetailItem> orderDetailItem = new HashSet<OrderDetailItem>(); from OrderDetail od where od=订单号