From c91708c1c095cd7f3191cc8372ca04883d294e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 18 Aug 2023 17:22:57 +0200 Subject: [PATCH] Add missing proxy hints for Hibernate native query This commit contributes proxy hints needed by SharedEntityManagerCreator for org.hibernate.query.sql.internal.NativeQueryImpl interfaces. A related smoke test has been contributed via spring-projects/spring-aot-smoke-tests#188. Closes gh-29603 --- .../orm/jpa/EntityManagerRuntimeHints.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java index 3164a36c963c..eb6e204028d2 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java @@ -39,6 +39,8 @@ class EntityManagerRuntimeHints implements RuntimeHintsRegistrar { private static final String QUERY_SQM_IMPL_CLASS_NAME = "org.hibernate.query.sqm.internal.QuerySqmImpl"; + private static final String NATIVE_QUERY_IMPL_CLASS_NAME = "org.hibernate.query.sql.internal.NativeQueryImpl"; + @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { if (ClassUtils.isPresent(HIBERNATE_SESSION_FACTORY_CLASS_NAME, classLoader)) { @@ -61,5 +63,11 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) { } catch (ClassNotFoundException ignored) { } + try { + Class clazz = ClassUtils.forName(NATIVE_QUERY_IMPL_CLASS_NAME, classLoader); + hints.proxies().registerJdkProxy(ClassUtils.getAllInterfacesForClass(clazz, classLoader)); + } + catch (ClassNotFoundException ignored) { + } } }