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.
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;
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.