Skip to content

Commit 44de925

Browse files
committed
Add reflection hints for SpringPersistenceUnitInfo
Fixes gh-35655
1 parent 22ecab5 commit 44de925

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.orm.jpa.persistenceunit;
18+
19+
20+
import org.jspecify.annotations.Nullable;
21+
22+
import org.springframework.aot.hint.MemberCategory;
23+
import org.springframework.aot.hint.RuntimeHints;
24+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
25+
26+
/**
27+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
28+
* the {@link SpringPersistenceUnitInfo}.
29+
*
30+
* @author Brian Clozel
31+
* @since 7.0
32+
*/
33+
public class SpringPersistenceUnitInfoRuntimeHints implements RuntimeHintsRegistrar {
34+
35+
@Override
36+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
37+
hints.reflection().registerType(SpringPersistenceUnitInfo.class, MemberCategory.INVOKE_PUBLIC_METHODS);
38+
hints.reflection().registerType(MutablePersistenceUnitInfo.class, MemberCategory.INVOKE_PUBLIC_METHODS);
39+
}
40+
41+
}

spring-orm/src/main/resources/META-INF/spring/aot.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
22
org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypesBeanRegistrationAotProcessor
33

44
org.springframework.aot.hint.RuntimeHintsRegistrar=\
5-
org.springframework.orm.jpa.EntityManagerRuntimeHints
5+
org.springframework.orm.jpa.EntityManagerRuntimeHints,\
6+
org.springframework.orm.jpa.persistenceunit.SpringPersistenceUnitInfoRuntimeHints
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.orm.jpa.persistenceunit;
18+
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.aot.hint.RuntimeHints;
23+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
24+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
25+
import org.springframework.beans.factory.aot.AotServices;
26+
import org.springframework.util.ClassUtils;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Tests for {@link SpringPersistenceUnitInfoRuntimeHints}.
32+
*
33+
* @author Brian Clozel
34+
*/
35+
class SpringPersistenceUnitInfoRuntimeHintsTests {
36+
37+
private final RuntimeHints hints = new RuntimeHints();
38+
39+
@BeforeEach
40+
void setup() {
41+
AotServices.factories().load(RuntimeHintsRegistrar.class)
42+
.forEach(registrar -> registrar.registerHints(this.hints,
43+
ClassUtils.getDefaultClassLoader()));
44+
}
45+
46+
@Test
47+
void springPersistenceUnitInfoHasReflectionHints() {
48+
assertThat(RuntimeHintsPredicates.reflection()
49+
.onMethodInvocation(SpringPersistenceUnitInfo.class, "setPersistenceProviderPackageName"))
50+
.accepts(this.hints);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)