hibernate之 DetachedCriteria实现多表查询

DetachedCriteria detachedCriteria = DetachedCriteria
			.forClass(ExternalSysOrderInfo.class);
	detachedCriteria.add(Restrictions.eq("serviceId", serviceId));
	detachedCriteria.add(Restrictions.eq("orderNo", billno));
	// singleOrder : endDate is null
	detachedCriteria.add(Restrictions.between("orderDate",
			getStartGregorianTime(beginDate),
			getEndGregorianTime(beginDate)));
	ProjectionList projectionList = Projections.projectionList();
	projectionList.add(Property.forName("orderState"));
	projectionList.add(Property.forName("VT.tradeMoney"));
	projectionList.add(Property.forName("orderNo"));
	projectionList.add(Property.forName("VT.beginDate"));
	projectionList.add(Property.forName("VT.endDate"));

	detachedCriteria.createAlias("vbaoTrade", "VT").setProjection(
			projectionList);

	try {
		List list = getHibernateTemplate().findByCriteria(detachedCriteria);
		if (list != null && list.size() > 0) {
			System.out.println("list size  is  :  " + list.size());
			return new ExtSettleDto((Object[]) list.get(0));
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;

 

ExtSettleDto.java

	public ExtSettleDto(Object[] object){
		this.state = (String) object[0];
		this.money = (Double) object[1];
		this.billno = (String) object[2];
		this.orderDate = (Date) object[3];
		this.dealDate = (Date) object[4];
	}

 

 

你可能感兴趣的:(Hibernate)