Skip to content

Commit 7a5d3a5

Browse files
committed
Refine EntityManagerRuntimeHints for Hibernate 7.1+
This commit adds support for Hibernate 7.1+ SqmQueryImpl class in EntityManagerRuntimeHints, keeps the support for the former QuerySqmImpl class for Hibernate 7.0 compatibility and adds a related test. Closes gh-35462
1 parent e89056c commit 7a5d3a5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ class EntityManagerRuntimeHints implements RuntimeHintsRegistrar {
3939

4040
private static final String ENTITY_MANAGER_FACTORY_CLASS_NAME = "jakarta.persistence.EntityManagerFactory";
4141

42+
// Up to Hibernate 7.0
4243
private static final String QUERY_SQM_IMPL_CLASS_NAME = "org.hibernate.query.sqm.internal.QuerySqmImpl";
4344

45+
// As of Hibernate 7.1
46+
private static final String SQM_QUERY_IMPL_CLASS_NAME = "org.hibernate.query.sqm.internal.SqmQueryImpl";
47+
4448
private static final String NATIVE_QUERY_IMPL_CLASS_NAME = "org.hibernate.query.sql.internal.NativeQueryImpl";
4549

4650

@@ -66,6 +70,12 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
6670
}
6771
catch (ClassNotFoundException ignored) {
6872
}
73+
try {
74+
Class<?> clazz = ClassUtils.forName(SQM_QUERY_IMPL_CLASS_NAME, classLoader);
75+
hints.proxies().registerJdkProxy(ClassUtils.getAllInterfacesForClass(clazz, classLoader));
76+
}
77+
catch (ClassNotFoundException ignored) {
78+
}
6979
try {
7080
Class<?> clazz = ClassUtils.forName(NATIVE_QUERY_IMPL_CLASS_NAME, classLoader);
7181
hints.proxies().registerJdkProxy(ClassUtils.getAllInterfacesForClass(clazz, classLoader));

spring-orm/src/test/java/org/springframework/orm/jpa/EntityManagerRuntimeHintsTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import jakarta.persistence.EntityManagerFactory;
2020
import org.hibernate.Session;
2121
import org.hibernate.SessionFactory;
22+
import org.hibernate.query.CommonQueryContract;
23+
import org.hibernate.query.SelectionQuery;
24+
import org.hibernate.query.hql.spi.SqmQueryImplementor;
25+
import org.hibernate.query.spi.DomainQueryExecutionContext;
26+
import org.hibernate.query.sqm.spi.InterpretationsKeySource;
2227
import org.junit.jupiter.api.BeforeEach;
2328
import org.junit.jupiter.api.Test;
2429

@@ -63,4 +68,14 @@ void entityManagerFactoryHasReflectionHints() {
6368
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(EntityManagerFactory.class, "getCriteriaBuilder")).accepts(this.hints);
6469
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(EntityManagerFactory.class, "getMetamodel")).accepts(this.hints);
6570
}
71+
72+
@Test
73+
void sqmQueryHints() {
74+
assertThat(RuntimeHintsPredicates.proxies().forInterfaces(
75+
SqmQueryImplementor.class,
76+
InterpretationsKeySource.class,
77+
DomainQueryExecutionContext.class,
78+
SelectionQuery.class,
79+
CommonQueryContract.class)).accepts(this.hints);
80+
}
6681
}

0 commit comments

Comments
 (0)