Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register reflection hints for JPA persistence callbacks #29348

Closed
christophstrobl opened this issue Oct 18, 2022 · 0 comments
Closed

Register reflection hints for JPA persistence callbacks #29348

christophstrobl opened this issue Oct 18, 2022 · 0 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Milestone

Comments

@christophstrobl
Copy link
Member

Next to registering hints for data binding (getter/setter) the PersistenceManagedTypesBeanRegistrationAotProcessor should also inspect methods for the presence of persistence annotations like @jakarta.persistence.PreRemove and include those methods.

Currently methods like the following do not show up in the generated reflect-config and won't be invoked by the persistence provider. Additionally it causes trouble with kotlin.reflect as outlined below.

@Entity
@Table(name = "tag")
class Tag(@Id val name: String, var color: Color) {

	@ManyToMany(mappedBy = "tags", fetch = FetchType.LAZY)
	private val notebooks: Set<Notebook> = emptySet()

	@PreRemove
	fun preRemove() {
		notebooks.forEach { notebook -> notebook.tags.remove(this) }
	}

        // ...
}
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Could not compute caller for function: public final fun preRemove(): kotlin.Unit defined in com.example.data.jpa.Tag[DeserializedSimpleFunctionDescriptor@8ff24cf] (member = null)
	at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:88) ~[na:na]
	at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:61) ~[na:na]
	at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(ReflectProperties.java:63) ~[na:na]
	at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:32) ~[spring-data-jpa-graalvm-native:1.7.20-release-201(1.7.20)]
	at kotlin.reflect.jvm.internal.KFunctionImpl.getCaller(KFunctionImpl.kt:61) ~[na:na]
	at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:63) ~[na:na]
	at kotlin.reflect.jvm.ReflectJvmMapping.getKotlinFunction(ReflectJvmMapping.kt:136) ~[na:na]
	at org.springframework.core.MethodParameter$KotlinDelegate.getGenericReturnType(MethodParameter.java:914) ~[na:na]
	at org.springframework.core.MethodParameter.getGenericParameterType(MethodParameter.java:510) ~[na:na]
	at org.springframework.core.SerializableTypeWrapper$MethodParameterTypeProvider.getType(SerializableTypeWrapper.java:291) ~[na:na]
	at org.springframework.core.SerializableTypeWrapper.forTypeProvider(SerializableTypeWrapper.java:107) ~[na:na]
	at org.springframework.core.ResolvableType.forType(ResolvableType.java:1413) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1334) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1316) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.core.ResolvableType.forMethodParameter(ResolvableType.java:1283) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.core.ResolvableType.forMethodReturnType(ResolvableType.java:1243) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:80) ~[na:na]
	at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:110) ~[na:na]
	at org.springframework.beans.CachedIntrospectionResults.buildGenericTypeAwarePropertyDescriptor(CachedIntrospectionResults.java:404) ~[na:na]
	at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:283) ~[na:na]
	at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:158) ~[na:na]
	at org.springframework.beans.BeanUtils.getPropertyDescriptors(BeanUtils.java:489) ~[na:na]
	at org.springframework.data.mapping.context.AbstractMappingContext.doAddPersistentEntity(AbstractMappingContext.java:414) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:379) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:280) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:206) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:92) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$6(RepositoryFactoryBeanSupport.java:282) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at java.util.Optional.ifPresent(Optional.java:178) ~[spring-data-jpa-graalvm-native:na]
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:282) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:132) ~[spring-data-jpa-graalvm-native:3.0.0-RC1]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1799) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749) ~[spring-data-jpa-graalvm-native:6.0.0-SNAPSHOT]
	... 30 common frames omitted

Related issue: spring-projects/spring-data-commons#2717

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 18, 2022
@sdeleuze sdeleuze self-assigned this Oct 18, 2022
@sdeleuze sdeleuze added the theme: aot An issue related to Ahead-of-time processing label Oct 18, 2022
@sdeleuze sdeleuze changed the title PersistenceManagedTypesBeanRegistrationAotProcessor should register reflection for persistence annotated methods. PersistenceManagedTypesBeanRegistrationAotProcessor should register reflection for persistence callbacks Oct 18, 2022
@sdeleuze sdeleuze added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 18, 2022
@sdeleuze sdeleuze added this to the 6.0.0-RC2 milestone Oct 18, 2022
@sdeleuze sdeleuze changed the title PersistenceManagedTypesBeanRegistrationAotProcessor should register reflection for persistence callbacks Register reflection hints for JPA persistence callbacks Oct 18, 2022
sdeleuze added a commit to sdeleuze/spring-aot-smoke-tests that referenced this issue Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) theme: aot An issue related to Ahead-of-time processing type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants