HHH-16749 Reproducer for incorrect function argument domain type
This commit is contained in:
parent
70d8b8b10d
commit
6ed858a461
|
@ -23,22 +23,44 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
|
package org.hibernate.orm.test.annotations.type.dynamicparameterized;
|
||||||
|
|
||||||
import java.util.Date;
|
import org.hibernate.boot.model.FunctionContributions;
|
||||||
|
import org.hibernate.boot.model.FunctionContributor;
|
||||||
|
import org.hibernate.metamodel.mapping.BasicValuedMapping;
|
||||||
|
import org.hibernate.metamodel.model.domain.BasicDomainType;
|
||||||
|
import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource;
|
||||||
|
import org.hibernate.query.ReturnableType;
|
||||||
|
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
|
||||||
|
import org.hibernate.query.sqm.tree.SqmTypedNode;
|
||||||
|
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||||
|
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.type.CustomType;
|
||||||
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Daniel Gredler
|
* @author Daniel Gredler
|
||||||
|
* @author Jan-Willem Gmelig Meyling
|
||||||
|
* @author Sayra Ranjha
|
||||||
*/
|
*/
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
annotatedClasses = { AbstractEntity.class, Entity1.class, Entity2.class }
|
annotatedClasses = { AbstractEntity.class, Entity1.class, Entity2.class }
|
||||||
)
|
)
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
|
@BootstrapServiceRegistry(
|
||||||
|
javaServices = @BootstrapServiceRegistry.JavaService(
|
||||||
|
role = FunctionContributor.class,
|
||||||
|
impl = DynamicParameterizedTypeTest.FunctionContributorImpl.class
|
||||||
|
)
|
||||||
|
)
|
||||||
public class DynamicParameterizedTypeTest {
|
public class DynamicParameterizedTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,4 +97,36 @@ public class DynamicParameterizedTypeTest {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMetamodel(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(session -> {
|
||||||
|
List resultList = session.createQuery("select test_func1(a.entity1_Prop3) from Entity1 a").getResultList();
|
||||||
|
assertNotNull(resultList);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class FunctionContributorImpl implements FunctionContributor {
|
||||||
|
@Override
|
||||||
|
public void contributeFunctions(FunctionContributions functionContributions) {
|
||||||
|
functionContributions.getFunctionRegistry()
|
||||||
|
.patternDescriptorBuilder( "test_func1", "?1" )
|
||||||
|
.setReturnTypeResolver(new FunctionReturnTypeResolver() {
|
||||||
|
@Override
|
||||||
|
public ReturnableType<?> resolveFunctionReturnType(ReturnableType<?> impliedType, List<? extends SqmTypedNode<?>> arguments, TypeConfiguration typeConfiguration) {
|
||||||
|
SqmTypedNode<?> sqmTypedNode = arguments.get(0);
|
||||||
|
BasicDomainType sqmPathType = ((BasicSqmPathSource) sqmTypedNode.getNodeType()).getSqmPathType();
|
||||||
|
assertInstanceOf(CustomType.class, sqmPathType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue