HHH-18102 Patch fixing the problem

This commit is contained in:
Cedomir Igaly 2024-05-13 12:02:13 +02:00 committed by Gavin King
parent 6bf358d324
commit 9f06bbb69e
3 changed files with 28 additions and 10 deletions

View File

@ -205,17 +205,17 @@ public class BasicDotIdentifierConsumer implements DotIdentifierConsumer {
final String prefix = path.substring( 0, splitPosition );
final String terminal = path.substring( splitPosition + 1 );
final EnumJavaType<?> enumType = jpaMetamodel.getEnumType( prefix );
if ( enumType != null ) {
return new SqmEnumLiteral(
jpaMetamodel.enumValue( enumType, terminal ),
enumType,
terminal,
nodeBuilder
);
}
try {
final EnumJavaType<?> enumType = jpaMetamodel.getEnumType( prefix );
if ( enumType != null ) {
return new SqmEnumLiteral(
jpaMetamodel.enumValue( enumType, terminal ),
enumType,
terminal,
nodeBuilder
);
}
final Class<?> namedClass =
creationContext.getServiceRegistry()
.requireService( ClassLoaderService.class )

View File

@ -118,6 +118,7 @@ import org.hibernate.type.spi.TypeConfiguration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@ -286,6 +287,8 @@ public abstract class MockSessionFactory
abstract boolean isEnum(String className);
abstract boolean isEnumConstant(String className, String terminal);
abstract boolean isFieldDefined(String qualifiedClassName, String fieldName);
abstract boolean isConstructorDefined(String qualifiedClassName, List<Type> argumentTypes);
@ -843,6 +846,9 @@ public abstract class MockSessionFactory
@Override
public <E extends Enum<E>> E enumValue(EnumJavaType<E> enumType, String enumValueName) {
if ( !isEnumConstant( enumType.getTypeName(), enumValueName ) ) {
throw new IllegalArgumentException( "No enum constant " + enumType.getTypeName() + "." + enumValueName );
}
return null;
}

View File

@ -595,6 +595,18 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory {
return typeElement != null && typeElement.getKind() == ElementKind.ENUM;
}
@Override
boolean isEnumConstant(String className, String terminal) {
final TypeElement typeElement = elementUtil.getTypeElement(className);
if (typeElement == null || typeElement.getKind() != ElementKind.ENUM) {
return false;
}
return typeElement.getEnclosedElements()
.stream()
.filter(e -> terminal.equals(e.getSimpleName().toString()))
.anyMatch(e -> e.getKind() == ElementKind.ENUM_CONSTANT);
}
private static boolean isEmbeddableType(TypeElement type) {
return hasAnnotation(type, "Embeddable");
}