Bug 104 : lookup property paths in BeanDescriptor.findBeanProperty
Priority 
High
Reported Version 
 
Logged By 
imario
Status 
Fixed
Fixed Version 
1.2.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
15/04/2009
Updated 
15/04/2009
Type 
Bug
 
Attachments 
No attachments

Hi!

When trying to Query.select() a property within an embedded Key (composite key), this property is missing from the list of selected columns.

The problem can be located in BeanDescriptor.findBeanProperty which is not able to find columns of embedded properties e.g. "key.customerId".

The following patch will lookup the whole property path and drill down it if possible. e.g. "key" is a BeanProperty of type BeanPropertyAssoc and thus the further lookup is delegated to the targetDescription.

Ciao,
Mario

Index: ../ebean/src/com/avaje/ebean/server/deploy/BeanDescriptor.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/BeanDescriptor.java (revision 210)
+++ ../ebean/src/com/avaje/ebean/server/deploy/BeanDescriptor.java Wed Apr 15 13:26:54 CEST 2009
@@ -986,14 +985,33 @@
*


*/
public BeanProperty findBeanProperty(String propName) {
+
+ int basePos = propName.indexOf('.');
+ if (basePos > -1) {
+ String baseName = propName.substring(0, basePos);
+ String propertyName = propName.substring(basePos+1);
+
+ BeanProperty prop = _findBeanProperty(baseName);
+ if (prop != null && prop instanceof BeanPropertyAssoc) {
+ return ((BeanPropertyAssoc) prop).getTargetDescriptor().findBeanProperty(propertyName);
+ }
+
+ return null;
+ }
+
+ return _findBeanProperty(propName);
+ }
+
+ private BeanProperty _findBeanProperty(String propName) {
+
- BeanProperty prop = (BeanProperty) propMap.get(propName);
- if (prop == null && inheritInfo != null) {
- // search in sub types...
- return inheritInfo.findSubTypeProperty(propName);
- }
- return prop;
- }
-
+ BeanProperty prop = (BeanProperty) propMap.get(propName);
+ if (prop == null && inheritInfo != null) {
+ // search in sub types...
+ return inheritInfo.findSubTypeProperty(propName);
+ }
+ return prop;
+ }
+
/**
* Return the name of the server this BeanDescriptor belongs to.
*/

 
Rob 25 Apr 23:12
Fixed in HEAD

This is now fixed in HEAD.

woResponse

Upload a file