Fix issues with min/max element/index in the select clause
This commit is contained in:
parent
e0a35287c9
commit
dc65d041d1
|
@ -3755,12 +3755,23 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
creationContext
|
||||
)
|
||||
);
|
||||
final String compatibleTableExpression;
|
||||
if ( modelPart instanceof BasicValuedModelPart ) {
|
||||
compatibleTableExpression = ( (BasicValuedModelPart) modelPart ).getContainingTableExpression();
|
||||
}
|
||||
else if ( modelPart instanceof EmbeddableValuedModelPart ) {
|
||||
compatibleTableExpression = ( (EmbeddableValuedModelPart) modelPart ).getContainingTableExpression();
|
||||
}
|
||||
else {
|
||||
compatibleTableExpression = null;
|
||||
}
|
||||
lateralTableGroup = new QueryPartTableGroup(
|
||||
queryPath,
|
||||
null,
|
||||
subQuerySpec,
|
||||
identifierVariable,
|
||||
columnNames,
|
||||
compatibleTableExpression,
|
||||
true,
|
||||
false,
|
||||
creationContext.getSessionFactory()
|
||||
|
@ -3801,7 +3812,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
}
|
||||
parentFromClauseAccess.registerTableGroup( lateralTableGroup.getNavigablePath(), lateralTableGroup );
|
||||
if ( jdbcTypeCount == 1 ) {
|
||||
return resultColumnReferences.get( 0 );
|
||||
return new BasicValuedPathInterpretation<>(
|
||||
resultColumnReferences.get( 0 ),
|
||||
queryPath,
|
||||
(BasicValuedModelPart) modelPart,
|
||||
lateralTableGroup
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new SqlTuple( resultColumnReferences, modelPart );
|
||||
|
@ -3813,7 +3829,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
}
|
||||
final QueryPartTableReference tableReference = (QueryPartTableReference) lateralTableGroup.getPrimaryTableReference();
|
||||
if ( jdbcTypeCount == 1 ) {
|
||||
return new ColumnReference(
|
||||
return new BasicValuedPathInterpretation<>(
|
||||
new ColumnReference(
|
||||
identifierVariable,
|
||||
tableReference.getColumnNames().get( 0 ),
|
||||
false,
|
||||
|
@ -3821,6 +3838,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
null,
|
||||
modelPart.getJdbcMappings().get( 0 ),
|
||||
creationContext.getSessionFactory()
|
||||
),
|
||||
queryPath,
|
||||
(BasicValuedModelPart) modelPart,
|
||||
lateralTableGroup
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.sql.ast.tree.from;
|
|||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
|
@ -22,6 +23,7 @@ import org.hibernate.sql.ast.tree.select.QueryPart;
|
|||
public class QueryPartTableGroup extends AbstractTableGroup {
|
||||
|
||||
private final QueryPartTableReference queryPartTableReference;
|
||||
private final String compatibleTableExpression;
|
||||
|
||||
public QueryPartTableGroup(
|
||||
NavigablePath navigablePath,
|
||||
|
@ -32,6 +34,28 @@ public class QueryPartTableGroup extends AbstractTableGroup {
|
|||
boolean lateral,
|
||||
boolean canUseInnerJoins,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
this(
|
||||
navigablePath,
|
||||
tableGroupProducer,
|
||||
queryPart,
|
||||
sourceAlias,
|
||||
columnNames,
|
||||
null,
|
||||
lateral,
|
||||
canUseInnerJoins,
|
||||
sessionFactory
|
||||
);
|
||||
}
|
||||
|
||||
public QueryPartTableGroup(
|
||||
NavigablePath navigablePath,
|
||||
TableGroupProducer tableGroupProducer,
|
||||
QueryPart queryPart,
|
||||
String sourceAlias,
|
||||
List<String> columnNames,
|
||||
String compatibleTableExpression, boolean lateral,
|
||||
boolean canUseInnerJoins,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
super(
|
||||
canUseInnerJoins,
|
||||
navigablePath,
|
||||
|
@ -40,6 +64,7 @@ public class QueryPartTableGroup extends AbstractTableGroup {
|
|||
null,
|
||||
sessionFactory
|
||||
);
|
||||
this.compatibleTableExpression = compatibleTableExpression;
|
||||
this.queryPartTableReference = new QueryPartTableReference(
|
||||
queryPart,
|
||||
sourceAlias,
|
||||
|
@ -60,7 +85,7 @@ public class QueryPartTableGroup extends AbstractTableGroup {
|
|||
String tableExpression,
|
||||
boolean allowFkOptimization,
|
||||
boolean resolve) {
|
||||
if ( tableExpression == null ) {
|
||||
if ( Objects.equals( tableExpression, compatibleTableExpression ) ) {
|
||||
return getPrimaryTableReference();
|
||||
}
|
||||
for ( TableGroupJoin tableGroupJoin : getNestedTableGroupJoins() ) {
|
||||
|
|
Loading…
Reference in New Issue