RawSql rawSql = RawSqlBuilder .parse("select c.customer_id, count(*) as totalContacts from contact c group by c.customer_id") .columnMapping("c.customer_id", "customer") //.columnMapping("r.name", "name") .create(); Query<CustomerAggregate> query = Ebean.find(CustomerAggregate.class); query.setRawSql(rawSql);
So with RawSql the columns need to be mapped to simple properties (due to full support of partial objects).
.columnMapping("c.customer_id", "customer")
This is the problem, it needs to map to:
.columnMapping("c.customer_id", "customer.id")
Ebean will catch this type of mapping error and give a better error message.
So the error thrown now is:
javax.persistence.PersistenceException:
Column [c.customer_id] mapped to complex Property[customer]. It should be mapped to a simple property (proably the Id property).
at com.avaje.ebeaninternal.server.query.CQueryBuilder.createRawSqlSqlTree(CQueryBuilder.java:341)
fixed in HEAD.