Bug 295 : Better error message mapping RawSql id property to a bean
Priority 
Medium
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
2.7.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
17/05/2010
Updated 
17/05/2010
Type 
Bug
 
Attachments 
No attachments
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);
 
Rob 17 May 05:20
Mapping

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.

Rob 17 May 05:21
Error thrown now:

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)

Rob 20 May 04:31
Fixed in HEAD

fixed in HEAD.

woResponse

Upload a file