HHH-17729 move validation of constructors in HQL instantiations to SemanticQueryBuilder

fix tests
This commit is contained in:
Gavin King 2024-02-11 15:03:30 +01:00
parent 1a9ec1d0ad
commit 766234d281
2 changed files with 16 additions and 16 deletions

View File

@ -138,6 +138,11 @@ public class ToHqlStringTest {
public Integer id;
public String name;
public TestDto(Integer id, String name) {
this.id = id;
this.name = name;
}
}
@Entity(name = "TestEntity")

View File

@ -11,8 +11,8 @@ import java.util.Map;
import org.hibernate.orm.test.query.sqm.BaseSqmUnitTest;
import org.hibernate.orm.test.query.sqm.domain.ConstructedLookupListItem;
import org.hibernate.orm.test.query.sqm.domain.InjectedLookupListItem;
import org.hibernate.orm.test.query.sqm.domain.NestedCtorLookupListItem;
import org.hibernate.query.SemanticException;
import org.hibernate.query.sqm.DynamicInstantiationNature;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation;
@ -29,6 +29,7 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Steve Ebersole
@ -241,21 +242,15 @@ public class DynamicInstantiationTests extends BaseSqmUnitTest {
@Test
public void testSimpleInjectedInstantiation() {
// todo (6.0) : this should blow up as early as possible - no aliases for bean-injection-based dynamic-instantiation
// atm this does not fail until later when building the SQL AST
SqmSelectStatement<?> statement = interpretSelect(
"select new org.hibernate.orm.test.query.sqm.domain.InjectedLookupListItem( e.id, e.theString ) from EntityOfBasics e"
);
assertEquals( 1, statement.getQuerySpec().getSelectClause().getSelections().size() );
final SqmDynamicInstantiation<?> dynamicInstantiation = TestingUtil.cast(
statement.getQuerySpec().getSelectClause().getSelections().get( 0 ).getSelectableNode(),
SqmDynamicInstantiation.class
);
assertThat( dynamicInstantiation.getInstantiationTarget().getNature(), is( DynamicInstantiationNature.CLASS ) );
assertThat( dynamicInstantiation.getInstantiationTarget().getJavaType(), is( equalTo( InjectedLookupListItem.class ) ) );
assertThat( dynamicInstantiation.getArguments(), hasSize( 2 ) );
try {
interpretSelect(
"select new org.hibernate.orm.test.query.sqm.domain.InjectedLookupListItem( e.id, e.theString ) from EntityOfBasics e"
);
fail("no constructor or aliases");
}
catch (SemanticException se) {
// should fail
}
}
}