fix several bugs in findSingleAttibute (#980)

* add test case for distinct on id property

* suggested fix for "select distinct id"

* add test case for distinct with fetch

* FIX: .setDistinct(true) can be used in conjunction with fetch() now

* add test case for distinct with beans that have a disriminator column

* FIX: discriminator column is only read if also Id is read.

* fine tuned the test case

* added test cases for findSingleAttributeList without distinct

* improved fix to support also findSingleAttribute without distinct

* ADD: Bonus test case - assertion not yet verified
This commit is contained in:
Roland Praml
2017-02-26 12:37:36 +13:00
committed by Rob Bygrave
parent 40ca179509
commit a46e086dc4
6 changed files with 171 additions and 13 deletions
@@ -322,7 +322,9 @@ public class SqlTreeBuilder {
return new SqlTreeNodeManyRoot(prefix, (BeanPropertyAssocMany<?>) prop, props, myList, temporalMode, disableLazyLoad);
} else {
return new SqlTreeNodeBean(prefix, prop, props, myList, temporalMode, disableLazyLoad);
// do not read Id on child beans (e.g. when used with fetch())
boolean withId = (query == null || !query.isSingleAttribute());
return new SqlTreeNodeBean(prefix, prop, props, myList, withId, temporalMode, disableLazyLoad);
}
}
@@ -438,7 +440,7 @@ public class SqlTreeBuilder {
p = desc.findBeanProperty("id");
selectProps.add(p);
} else if (p.isId()) {
} else if (p.isId() && (query == null || !query.isSingleAttribute())) {
// do not bother to include id for normal queries as the
// id is always added (except for subQueries)