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 Integer id;
public String name; public String name;
public TestDto(Integer id, String name) {
this.id = id;
this.name = name;
}
} }
@Entity(name = "TestEntity") @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.BaseSqmUnitTest;
import org.hibernate.orm.test.query.sqm.domain.ConstructedLookupListItem; 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.orm.test.query.sqm.domain.NestedCtorLookupListItem;
import org.hibernate.query.SemanticException;
import org.hibernate.query.sqm.DynamicInstantiationNature; import org.hibernate.query.sqm.DynamicInstantiationNature;
import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.select.SqmDynamicInstantiation; 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.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize; import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -241,21 +242,15 @@ public class DynamicInstantiationTests extends BaseSqmUnitTest {
@Test @Test
public void testSimpleInjectedInstantiation() { 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( try {
interpretSelect(
"select new org.hibernate.orm.test.query.sqm.domain.InjectedLookupListItem( e.id, e.theString ) from EntityOfBasics e" "select new org.hibernate.orm.test.query.sqm.domain.InjectedLookupListItem( e.id, e.theString ) from EntityOfBasics e"
); );
assertEquals( 1, statement.getQuerySpec().getSelectClause().getSelections().size() ); fail("no constructor or aliases");
}
final SqmDynamicInstantiation<?> dynamicInstantiation = TestingUtil.cast( catch (SemanticException se) {
statement.getQuerySpec().getSelectClause().getSelections().get( 0 ).getSelectableNode(), // should fail
SqmDynamicInstantiation.class }
);
assertThat( dynamicInstantiation.getInstantiationTarget().getNature(), is( DynamicInstantiationNature.CLASS ) );
assertThat( dynamicInstantiation.getInstantiationTarget().getJavaType(), is( equalTo( InjectedLookupListItem.class ) ) );
assertThat( dynamicInstantiation.getArguments(), hasSize( 2 ) );
} }
} }