Bug 71 : autoFetchTuned does not correctly work with inherited tables
Priority 
High
Reported Version 
 
Logged By 
imario
Status 
Fixed
Fixed Version 
1.0.3
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
15/02/2009
Updated 
15/02/2009
Type 
Bug
 
Attachments 
No attachments

The autoFetch statistic seems not to be collected correctly in case of inherited tables.

On the first run of a query, where avaje reads all the fields, the data is collected correctly.
On the second run of the same query only the fields of the parent class get loaded. All the fields of the inherited class are ignored.

 
imario 15 Feb 13:52
patch for missing fields with inherited entities and autofetch

The main problem was in SqlTreeBuilder.java, there, the system checks if the fields for the select are really existent on the entity.
But this did not take into account that a property might come from an inherited entity.

The change is, that if a property can't be found, to simply ask the inheritors and get the property from there.

Not it works as expected.

Index: ../ebean/src/com/avaje/ebean/server/query/SqlTreeBuilder.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/query/SqlTreeBuilder.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/query/SqlTreeBuilder.java Sun Feb 15 14:40:32 CET 2009
@@ -262,7 +262,13 @@
String propName = it.next();
if (propName.length() > 0){
BeanProperty p = desc.getBeanProperty(propName);
+ if (p == null && desc.getInheritInfo() != null)
+ {
+ InheritInfo inheritInfo = desc.getInheritInfo();
+ p = inheritInfo.getSubTypeProperty(propName);
+ }
if (p == null) {
+
logger.log(Level.SEVERE, "property [" + propName + "] not found on " + desc
+ " for query - excluding it.");

Index: ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java
===================================================================
--- ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java (revision 127)
+++ ../ebean/src/com/avaje/ebean/server/deploy/InheritInfo.java Sun Feb 15 14:47:44 CET 2009
@@ -96,15 +96,16 @@
*/
public BeanProperty getSubTypeProperty(String propertyName) {

-// BeanProperty prop = descriptor.getBeanProperty(propertyName);
-// if (prop != null){
-// return prop;
-// }
-
- BeanProperty prop = null;
-
for (int i = 0, x=children.size(); i < x; i++) {
InheritInfo childInfo = children.get(i);
+
+ // see if this child has a property with given name ...
+ BeanProperty prop = childInfo.getBeanDescriptor().getBeanProperty(propertyName);
+ if (prop != null){
+ return prop;
+ }
+
+ // ... no, ask the next inheritance level
prop = childInfo.getSubTypeProperty(propertyName);
if (prop != null){
return prop;

Rob 19 Feb 08:19
Fixed in v1.0.3

Excellent. Fixed with a slight tweak to the code above.. by adding a findBeanProperty() method to BeanDescriptor (which performs the recursive search for the BeanProperty down the inheritance hierarchy.

Excellent work again Mario - thanks.

woResponse

Upload a file