有两个表Customer和Order 一对多,被配置成单向的一对多关系
customer(customer_id,name,address)
order(order_id,customer_id,ordernam,order_date)
Customer
+-------------+----------+---------+
| customer_id | name | address |
+-------------+----------+---------+
| 1 | ZHANGSAN | beijing |
| 2 | LISI | beijing |
| 3 | WANGWU | chengdu |
+-------------+----------+---------+
Order
+-------------+------------+-----------+
| order_id | customer_id| ordername | order_date
+-------------+------------+-----------+
| 1 | 1 | book | 2008-12-25
| 2 | 1 | pen | 2008-12-25
| 3 | 1 | computer | 2008-12-25
+-------------+------------+-----------+
customer.hbm.xml
</>
order.hbm.xml
现在我有一个查询需求:根据订单日期(order_date),还有customer_id,来查询出在一个时间段内,下过订单的顾客信息。
sql语句是这样的:select customer from customer c, order o where c.customer_id=o.customer_id and c.customer_id='' and o.order_date >= 'startDate' and o.order_date<='endDate'.
我在使用这样的HQL语句“ from Customer c, Order o where c.customer_id=o.customer and c.customer_id=:customerId and o.orderDate between :startDate and :endDate ”进行查询,得到相应的List里面包含一个长度为2的数组,数组中2个对象分别是包含Customer和Order的List,其结构是这样的:
List
--List
--List
这个结果和我想要的不一样,我想要的应该就只是List,现在我改如何修改HQL,来实现我的需求呢?
我知道根据上面已经有的结果List,可以在程序中得到我想要的List。但是我觉得这样做不是最好的。
大家有没有什么好的方法呢?