Skip to content

Commit 687c404

Browse files
committed
Merge branch '6.2.x'
2 parents 0552cdb + 5aec239 commit 687c404

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ private void contributeHints(RuntimeHints hints, @Nullable ClassLoader classLoad
137137
contributeConverterHints(hints, managedClass);
138138
contributeCallbackHints(hints, managedClass);
139139
contributeHibernateHints(hints, classLoader, managedClass);
140+
contributePackagePrivateHints(hints, managedClass);
140141
}
141142
catch (ClassNotFoundException ex) {
142143
throw new IllegalArgumentException("Failed to instantiate JPA managed class: " + managedClassName, ex);
@@ -234,6 +235,18 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader
234235
}
235236
}
236237

238+
private void contributePackagePrivateHints(RuntimeHints hints, Class<?> managedClass) {
239+
ReflectionHints reflection = hints.reflection();
240+
ReflectionUtils.doWithMethods(managedClass, method ->
241+
reflection.registerMethod(method, ExecutableMode.INVOKE),
242+
method -> {
243+
int modifiers = method.getModifiers();
244+
return !(java.lang.reflect.Modifier.isProtected(modifiers) ||
245+
java.lang.reflect.Modifier.isPrivate(modifiers) ||
246+
java.lang.reflect.Modifier.isPublic(modifiers));
247+
});
248+
}
249+
237250
@SuppressWarnings("unchecked")
238251
private static @Nullable Class<? extends Annotation> loadClass(String className, @Nullable ClassLoader classLoader) {
239252
try {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2002-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.domain;
18+
19+
import jakarta.persistence.Column;
20+
import jakarta.persistence.Entity;
21+
import jakarta.persistence.GeneratedValue;
22+
import jakarta.persistence.GenerationType;
23+
import jakarta.persistence.Id;
24+
25+
@Entity
26+
public class Car {
27+
28+
@Id
29+
@GeneratedValue(strategy = GenerationType.AUTO)
30+
private Integer id;
31+
32+
@Column
33+
private String model;
34+
35+
Integer getId() {
36+
return id;
37+
}
38+
39+
void setId(Integer id) {
40+
this.id = id;
41+
}
42+
43+
void setModel(String model) {
44+
this.model = model;
45+
}
46+
47+
String getModel() {
48+
return model;
49+
}
50+
}

spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.core.test.tools.TestCompiler;
3939
import org.springframework.orm.jpa.JpaVendorAdapter;
4040
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
41+
import org.springframework.orm.jpa.domain.Car;
4142
import org.springframework.orm.jpa.domain.DriversLicense;
4243
import org.springframework.orm.jpa.domain.Employee;
4344
import org.springframework.orm.jpa.domain.EmployeeCategoryConverter;
@@ -71,7 +72,7 @@ void processEntityManagerWithPackagesToScan() {
7172
"persistenceManagedTypes", PersistenceManagedTypes.class);
7273
assertThat(persistenceManagedTypes.getManagedClassNames()).containsExactlyInAnyOrder(
7374
DriversLicense.class.getName(), Person.class.getName(), Employee.class.getName(),
74-
EmployeeLocationConverter.class.getName());
75+
EmployeeLocationConverter.class.getName(), Car.class.getName());
7576
assertThat(persistenceManagedTypes.getManagedPackages()).isEmpty();
7677
assertThat(freshApplicationContext.getBean(
7778
JpaDomainConfiguration.class).scanningInvoked).isFalse();
@@ -104,6 +105,14 @@ void contributeJpaHints() {
104105
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(hints);
105106
assertThat(RuntimeHintsPredicates.reflection().onType(EmployeeLocation.class)
106107
.withMemberCategories(MemberCategory.ACCESS_DECLARED_FIELDS)).accepts(hints);
108+
assertThat(RuntimeHintsPredicates.reflection().onMethod(Car.class, "setId")
109+
.invoke()).accepts(hints);
110+
assertThat(RuntimeHintsPredicates.reflection().onMethod(Car.class, "getId")
111+
.invoke()).accepts(hints);
112+
assertThat(RuntimeHintsPredicates.reflection().onMethod(Car.class, "setModel")
113+
.invoke()).accepts(hints);
114+
assertThat(RuntimeHintsPredicates.reflection().onMethod(Car.class, "getModel")
115+
.invoke()).accepts(hints);
107116
});
108117
}
109118

spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesScannerTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.springframework.context.testfixture.index.CandidateComponentsTestClassLoader;
2424
import org.springframework.core.io.ClassPathResource;
2525
import org.springframework.core.io.DefaultResourceLoader;
26+
import org.springframework.orm.jpa.domain.Car;
2627
import org.springframework.orm.jpa.domain.DriversLicense;
2728
import org.springframework.orm.jpa.domain.Employee;
2829
import org.springframework.orm.jpa.domain.EmployeeLocationConverter;
@@ -52,7 +53,7 @@ void scanPackageWithOnlyEntities() {
5253
PersistenceManagedTypes managedTypes = this.scanner.scan("org.springframework.orm.jpa.domain");
5354
assertThat(managedTypes.getManagedClassNames()).containsExactlyInAnyOrder(
5455
Person.class.getName(), DriversLicense.class.getName(), Employee.class.getName(),
55-
EmployeeLocationConverter.class.getName());
56+
EmployeeLocationConverter.class.getName(), Car.class.getName());
5657
assertThat(managedTypes.getManagedPackages()).isEmpty();
5758
}
5859

@@ -66,6 +67,7 @@ void scanPackageInvokesManagedClassNamesFilter() {
6667
verify(filter).matches(DriversLicense.class.getName());
6768
verify(filter).matches(Employee.class.getName());
6869
verify(filter).matches(EmployeeLocationConverter.class.getName());
70+
verify(filter).matches(Car.class.getName());
6971
verifyNoMoreInteractions(filter);
7072
}
7173

0 commit comments

Comments
 (0)