Bug 34 : Query with partial properties, using a reference generates wrong sql select....
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
0.9.6
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
20/02/2008
Updated 
20/02/2008
Type 
Bug
 
Attachments 
No attachments

Example:
SELECT b.id, b.id, b.title, b.null, b.user_logged_id
FROM `b_bug` b
WHERE b.id = ?

Generated from...
Bug bug0 = Ebean.createQuery(Bug.class)
.setProperties("id, title, userLogged")
.setId(1l)
.findUnique();

 
Rob 20 Feb 21:33
Problem with com.avaje.ebean.server.query.SqlSelectClauseBuilder .... appendBaseSelect()

Specifically this should only append 'scalar' types (not associated ones).
In this case the userLogged is a @ManyToOne (associated one) so it should not be included at this point.

References (assoc one lazy loading references) are included in the query at the isIncludeBean() method.

Rob 20 Feb 21:35
Fixed in 0.9.5b

The correct generated sql is...

SELECT b.id, b.id, b.title, b.user_logged_id
FROM `b_bug` b
WHERE b.id = ?

Fixed in 0.9.5b

Rob 20 Feb 21:40
Ok, just noticed a related bug... The id column is in the select statement twice

This is because Ids are treated specially... the correct logic for appendBaseSelect() is to only include non-id base properties.

Just fixed that as well.

Rob 20 Feb 21:43
This is the correct sql ...

SELECT b.id, b.title
FROM `b_bug` b
WHERE b.id = ?

Rob 20 Feb 22:53
Note: Bug was introduced in 0.9.5

0.9.4 code explicitly only went through base properties.

Aka, this bug was introduced in 0.9.5.

woResponse

Upload a file