2. "REPORT" type entity bean
-----------------------------------------------
@Entity
@Sql(select = {
@SqlSelect(
name="default",
query="select order_id, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id"
)
})
public class OrderReport {
Integer orderId;
Double totalAmount;
public Integer getOrderId() {
return orderId;
}
public void setOrderId(Integer orderId) {
this.orderId = orderId;
}
public Double getTotalAmount() {
return totalAmount;
}
public void setTotalAmount(Double totalAmount) {
this.totalAmount = totalAmount;
}
}
....
List<OrderReport> list = Ebean.find(OrderReport.class)
.where().gt("order_qty", 1)
.having().gt("totalAmount", 20.50)
.findList();
// results in
select order_id, sum(order_qty*unit_price) as total_amount
from o_order_detail
where order_qty > ?
group by order_id
having total_amount > ?
Notes:
- The "order_qty" is not a known property (on the OrderReport) so it is goes into sql as is
- The "totalAmount" is a known property... so gets converted
- The DB column names are mapping to bean properties automatically via naming convention
- You can use a HAVING clauses
- The query name "default" is special ...