From fc6fca343543216ffe72affa44b27327cc37d0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=8Cedomir=20Igaly?= Date: Tue, 9 Jul 2024 10:13:32 +0200 Subject: [PATCH] HHH-18358 Properly resolving entity type literal in named query while generating metamodel --- .../processor/validation/MockSessionFactory.java | 8 ++++++++ .../processor/validation/ProcessorSessionFactory.java | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java index 7d963be616..103cd5c579 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockSessionFactory.java @@ -280,6 +280,8 @@ public abstract class MockSessionFactory abstract boolean isEntityDefined(String entityName); + abstract String findEntityName(String typeName); + abstract String qualifyName(String entityName); abstract boolean isAttributeDefined(String entityName, String fieldName); @@ -801,6 +803,12 @@ public abstract class MockSessionFactory } } + @Override + public ManagedDomainType managedType(String typeName) { + final String entityName = findEntityName( typeName ); + return entityName == null ? null : entity( entityName ); + } + @Override public String qualifyImportableName(String queryName) { if (isClassDefined(queryName)) { diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java index aa6f5e482c..abbbc9967a 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/ProcessorSessionFactory.java @@ -425,6 +425,16 @@ public abstract class ProcessorSessionFactory extends MockSessionFactory { return findEntityClass(entityName) != null; } + @Override + String findEntityName(String typeName) { + for ( final Map.Entry e : entityNameMappings.entrySet() ) { + if ( typeName.equals( e.getKey() ) || typeName.equals( e.getValue() ) ) { + return e.getKey(); + } + } + return null; + } + @Override String qualifyName(String entityName) { TypeElement entityClass = findEntityClass(entityName);