HHH-16647 allow unqualified use of query result type in HQL instantiation
This commit is contained in:
parent
addd88000c
commit
f673441ab3
|
@ -1306,11 +1306,13 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
|
|||
final SqmDynamicInstantiation<?> dynamicInstantiation;
|
||||
final ParseTree instantiationTarget = ctx.instantiationTarget().getChild( 0 );
|
||||
if ( instantiationTarget instanceof HqlParser.SimplePathContext ) {
|
||||
final String className = instantiationTarget.getText();
|
||||
String className = instantiationTarget.getText();
|
||||
if ( expectedResultType!=null && expectedResultType.getSimpleName().equals( className ) ) {
|
||||
className = expectedResultType.getName();
|
||||
}
|
||||
try {
|
||||
final JavaType<?> jtd = resolveInstantiationTargetJtd( className );
|
||||
dynamicInstantiation = SqmDynamicInstantiation.forClassInstantiation(
|
||||
jtd,
|
||||
resolveInstantiationTargetJtd( className ),
|
||||
creationContext.getNodeBuilder()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1920,4 +1920,23 @@ public class FunctionTests {
|
|||
);
|
||||
}
|
||||
|
||||
static class Pair {
|
||||
int integer; double floating;
|
||||
Pair(int integer, double floating) {
|
||||
this.integer = integer;
|
||||
this.floating = floating;
|
||||
}
|
||||
}
|
||||
static class Triple {
|
||||
int integer; double floating; String string;
|
||||
}
|
||||
@Test
|
||||
public void testInstantiateLocalClass(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
session.createSelectionQuery("select new Pair(theInt, theDouble) from EntityOfBasics", Pair.class).getResultList();
|
||||
session.createSelectionQuery("select new Triple(theInt as integer, theDouble as floating, 'hello' as string) from EntityOfBasics", Triple.class).getResultList();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue