mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1740 and #1744 Don't include the discriminator column on Inheritance query on a type that has no sub-types
Fix for #1740
This commit is contained in:
@@ -74,7 +74,7 @@ class AssocOneHelpRefInherit extends AssocOneHelp {
|
||||
@Override
|
||||
void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
|
||||
if (!subQuery) {
|
||||
if (!subQuery && inherit.hasChildren()) {
|
||||
// add discriminator column
|
||||
String relativePrefix = ctx.getRelativePrefix(property.getName());
|
||||
String tableAlias = ctx.getTableAlias(relativePrefix);
|
||||
|
||||
@@ -6,8 +6,8 @@ import io.ebeaninternal.server.deploy.id.IdBinder;
|
||||
import io.ebeaninternal.server.deploy.parse.DeployInheritInfo;
|
||||
import io.ebeaninternal.server.query.SqlTreeProperties;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -175,6 +175,16 @@ public class InheritInfo {
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this node has children.
|
||||
* <p>
|
||||
* When an inheritance node has no children then we don't need
|
||||
* the discriminator column as the type is effectively known.
|
||||
*/
|
||||
public boolean hasChildren() {
|
||||
return !children.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bean property additionally looking in the sub types.
|
||||
*/
|
||||
@@ -200,7 +210,6 @@ public class InheritInfo {
|
||||
|
||||
for (InheritInfo childInfo : children) {
|
||||
selectProps.add(childInfo.descriptor.propertiesLocal());
|
||||
|
||||
childInfo.addChildrenProperties(selectProps);
|
||||
}
|
||||
}
|
||||
@@ -209,9 +218,10 @@ public class InheritInfo {
|
||||
* Return the associated InheritInfo for this DB row read.
|
||||
*/
|
||||
public InheritInfo readType(DbReadContext ctx) throws SQLException {
|
||||
|
||||
String discValue = ctx.getDataReader().getString();
|
||||
return readType(discValue);
|
||||
if (!hasChildren()) {
|
||||
return this;
|
||||
}
|
||||
return readType(ctx.getDataReader().getString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +337,6 @@ public class InheritInfo {
|
||||
* Return the derived where for the discriminator.
|
||||
*/
|
||||
public String getWhere() {
|
||||
|
||||
return where;
|
||||
}
|
||||
|
||||
|
||||
@@ -199,9 +199,7 @@ public class DeployInheritInfo {
|
||||
public String getWhere() {
|
||||
|
||||
List<Object> discList = new ArrayList<>();
|
||||
|
||||
appendDiscriminator(discList);
|
||||
|
||||
return buildWhereLiteral(discList);
|
||||
}
|
||||
|
||||
|
||||
@@ -543,10 +543,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
}
|
||||
|
||||
if (readId) {
|
||||
if (!subQuery && inheritInfo != null) {
|
||||
if (!subQuery && inheritInfo != null && inheritInfo.hasChildren()) {
|
||||
ctx.appendColumn(inheritInfo.getDiscriminatorColumn());
|
||||
}
|
||||
|
||||
appendSelectId(ctx, idBinder.getBeanProperty());
|
||||
}
|
||||
appendSelect(ctx, subQuery, properties);
|
||||
|
||||
Reference in New Issue
Block a user