#1023 - Bug with findSingleAttributeList() when used against @ManyToOne / foreign key

This commit is contained in:
rob bygrave
2017-05-11 23:20:19 +12:00
parent 951e517caf
commit 711701932a
7 changed files with 54 additions and 14 deletions
@@ -54,7 +54,7 @@ class CQueryFetchSingleAttribute {
private int rowCount;
private final ScalarType<Object> scalarType;
private final ScalarType<?> scalarType;
/**
* Create the Sql select based on the request.
@@ -65,7 +65,7 @@ class CQueryFetchSingleAttribute {
this.sql = plan.getSql();
this.desc = request.getBeanDescriptor();
this.predicates = predicates;
this.scalarType = plan.getSingleProperty().getScalarType();
this.scalarType = plan.getSingleAttributeScalarType();
query.setGeneratedSql(sql);
}
@@ -11,6 +11,7 @@ import io.ebeaninternal.server.query.CQueryPlanStats.Snapshot;
import io.ebeaninternal.server.type.DataBind;
import io.ebeaninternal.server.type.DataReader;
import io.ebeaninternal.server.type.RsetDataReader;
import io.ebeaninternal.server.type.ScalarType;
import io.ebeaninternal.server.util.Md5;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -248,7 +249,7 @@ public class CQueryPlan {
return stats.getLastQueryTime();
}
BeanProperty getSingleProperty() {
return sqlTree.getRootNode().getSingleProperty();
ScalarType<?> getSingleAttributeScalarType() {
return sqlTree.getRootNode().getSingleAttributeScalarType();
}
}
@@ -3,9 +3,9 @@ package io.ebeaninternal.server.query;
import io.ebean.Version;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import io.ebeaninternal.server.type.ScalarType;
import java.sql.SQLException;
import java.util.List;
@@ -81,6 +81,6 @@ interface SqlTreeNode {
/**
* Return the property for singleAttribute query.
*/
BeanProperty getSingleProperty();
ScalarType<?> getSingleAttributeScalarType();
}
@@ -11,12 +11,14 @@ import io.ebeaninternal.api.SpiQuery.Mode;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import io.ebeaninternal.server.deploy.InheritInfo;
import io.ebeaninternal.server.deploy.TableJoin;
import io.ebeaninternal.server.deploy.id.IdBinder;
import io.ebeaninternal.server.type.ScalarType;
import java.sql.SQLException;
import java.sql.Timestamp;
@@ -58,7 +60,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
* False if report bean and has no id property.
*/
protected final boolean readId;
private final boolean disableLazyLoad;
protected final InheritInfo inheritInfo;
@@ -134,13 +136,19 @@ class SqlTreeNodeBean implements SqlTreeNode {
}
@Override
public BeanProperty getSingleProperty() {
public ScalarType<?> getSingleAttributeScalarType() {
if (properties == null || properties.length == 0) {
// if we have no property ask first children (in a distinct select with join)
// if we have also no children, NPE happens anyway.
return children[0].getSingleProperty();
return children[0].getSingleAttributeScalarType();
}
return properties[0];
if (properties[0] instanceof BeanPropertyAssocOne<?>) {
BeanPropertyAssocOne assocOne = (BeanPropertyAssocOne<?>)properties[0];
if (assocOne.isAssocId()) {
return assocOne.getTargetDescriptor().getIdProperty().getScalarType();
}
}
return properties[0].getScalarType();
}
private Map<String, String> createPathMap(String prefix, BeanDescriptor<?> desc) {
@@ -3,12 +3,12 @@ package io.ebeaninternal.server.query;
import io.ebean.Version;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import io.ebeaninternal.server.deploy.TableJoin;
import io.ebeaninternal.server.type.ScalarType;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -72,7 +72,7 @@ class SqlTreeNodeExtraJoin implements SqlTreeNode {
}
@Override
public BeanProperty getSingleProperty() {
public ScalarType<?> getSingleAttributeScalarType() {
throw new IllegalStateException("No expected");
}
@@ -3,13 +3,13 @@ package io.ebeaninternal.server.query;
import io.ebean.Version;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.BeanPropertyAssocOne;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import io.ebeaninternal.server.deploy.TableJoin;
import io.ebeaninternal.server.type.ScalarType;
import java.sql.SQLException;
import java.util.List;
@@ -41,7 +41,7 @@ class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
}
@Override
public BeanProperty getSingleProperty() {
public ScalarType<?> getSingleAttributeScalarType() {
throw new IllegalStateException("No expected");
}