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

Missing native hints for Hibernate Native Query proxy #29603

Closed
ahmedeewo opened this issue Nov 28, 2022 · 8 comments
Closed

Missing native hints for Hibernate Native Query proxy #29603

ahmedeewo opened this issue Nov 28, 2022 · 8 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

@ahmedeewo
Copy link

ahmedeewo commented Nov 28, 2022

In Spring Boot 3.0.0, jpa native query not working

    @Query(value = "SELECT * from user  where email = ?1 ;",nativeQuery = true)
    User findByEmail(String email);

with this error

com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.hibernate.query.sql.spi.NativeQueryImplementor, interface org.hibernate.query.spi.DomainQueryExecutionContext, interface org.hibernate.query.internal.ResultSetMappingResolutionContext, interface org.hibernate.query.spi.QueryImplementor, interface org.hibernate.query.SelectionQuery, interface org.hibernate.query.CommonQueryContract] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
        Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
@ahmedeewo ahmedeewo changed the title Native Queries not working Native Queries not working in JPA 3.0 native image Nov 28, 2022
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 28, 2022
@mp911de
Copy link
Member

mp911de commented Nov 29, 2022

Can you please attach the full stack trace?

@ahmedeewo
Copy link
Author

ahmedeewo commented Nov 29, 2022

Can you please attach the full stack trace?
thank you for response

com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.hibernate.query.sql.spi.NativeQueryImplementor, interface org.hibernate.query.spi.DomainQueryExecutionContext, interface org.hibernate.query.internal.ResultSetMappingResolutionContext, interface org.hibernate.query.spi.QueryImplementor, interface org.hibernate.query.SelectionQuery, interface org.hibernate.query.CommonQueryContract] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
        Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
        *__checkpoint ⇢ org.springframework.web.filter.reactive.ServerHttpObservationFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ com.demo.spring3.configs.CustomClientWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ AuthorizationWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ ExceptionTranslationWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ ServerRequestCacheWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ SecurityContextServerWebExchangeWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ ReactorContextWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ HttpHeaderWriterWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain]
        *__checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain]
        *__checkpoint ⇢ HTTP POST "/api/data/v1/oauth/token" [ExceptionHandlingWebHandler]
Original Stack Trace:
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.proxy.DynamicProxySupport.getProxyClass(DynamicProxySupport.java:171)
                at java.base@19.0.1/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:47)
                at java.base@19.0.1/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)
                at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:312)
                at jdk.proxy4/jdk.proxy4.$Proxy107.createNativeQuery(Unknown Source)
                at org.springframework.data.jpa.repository.query.NativeJpaQuery.createJpaQuery(NativeJpaQuery.java:74)
                at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:100)
                at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:234)
                at org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:193)
                at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:90)
                at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:148)
                at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:136)
                at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:136)
                at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:120)
                at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164)
                at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:77)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
                at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
                at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:134)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
                at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
                at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:218)
                at jdk.proxy4/jdk.proxy4.$Proxy68.getApiUserByKey(Unknown Source)
                at com.demo.spring3.resources.api.AuthController.user(AuthController.java:57)
                at java.base@19.0.1/java.lang.reflect.Method.invoke(Method.java:578)
                at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$invoke$0(InvocableHandlerMethod.java:145)
                at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:132)
                at reactor.core.publisher.MonoZip$ZipCoordinator.signal(MonoZip.java:293)
                at reactor.core.publisher.MonoZip$ZipInner.onNext(MonoZip.java:474)
                at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onNext(MonoPeekTerminal.java:180)
                at reactor.core.publisher.FluxDefaultIfEmpty$DefaultIfEmptySubscriber.onNext(FluxDefaultIfEmpty.java:122)
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onNext(FluxPeek.java:200)
                at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:74)
                at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:79)
                at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:158)
                at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onNext(FluxContextWrite.java:107)
                at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.onNext(FluxMapFuseable.java:299)
                at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onNext(FluxFilterFuseable.java:337)
                at reactor.core.publisher.Operators$BaseFluxToMonoOperator.completePossiblyEmpty(Operators.java:2034)
                at reactor.core.publisher.MonoCollect$CollectSubscriber.onComplete(MonoCollect.java:145)
                at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144)
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260)
                at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144)
                at reactor.netty.channel.FluxReceive.terminateReceiver(FluxReceive.java:481)
                at reactor.netty.channel.FluxReceive.drainReceiver(FluxReceive.java:273)
                at reactor.netty.channel.FluxReceive.request(FluxReceive.java:134)
                at reactor.core.publisher.FluxMap$MapSubscriber.request(FluxMap.java:164)
                at reactor.core.publisher.FluxPeek$PeekSubscriber.request(FluxPeek.java:138)
                at reactor.core.publisher.FluxMap$MapSubscriber.request(FluxMap.java:164)
                at reactor.core.publisher.Operators$BaseFluxToMonoOperator.request(Operators.java:2004)
                at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.request(FluxFilterFuseable.java:411)
                at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.request(FluxMapFuseable.java:360)
                at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.request(FluxContextWrite.java:136)
                at reactor.core.publisher.MonoFlatMap$FlatMapMain.request(MonoFlatMap.java:194)
                at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2304)
                at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onSubscribe(FluxOnErrorResume.java:74)
                at reactor.core.publisher.MonoFlatMap$FlatMapMain.onSubscribe(MonoFlatMap.java:117)
                at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onSubscribe(FluxContextWrite.java:101)
                at reactor.core.publisher.FluxMapFuseable$MapFuseableConditionalSubscriber.onSubscribe(FluxMapFuseable.java:265)
                at reactor.core.publisher.FluxFilterFuseable$FilterFuseableConditionalSubscriber.onSubscribe(FluxFilterFuseable.java:305)
                at reactor.core.publisher.Operators$BaseFluxToMonoOperator.onSubscribe(Operators.java:1988)
                at reactor.core.publisher.FluxMap$MapSubscriber.onSubscribe(FluxMap.java:92)
                at reactor.core.publisher.FluxPeek$PeekSubscriber.onSubscribe(FluxPeek.java:171)
                at reactor.core.publisher.FluxMap$MapSubscriber.onSubscribe(FluxMap.java:92)
                at reactor.netty.channel.FluxReceive.startReceiver(FluxReceive.java:172)
                at reactor.netty.channel.FluxReceive.lambda$subscribe$2(FluxReceive.java:151)
                at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174)
                at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:167)
                at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
                at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)
                at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
                at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
                at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
                at java.base@19.0.1/java.lang.Thread.run(Thread.java:1589)
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
                at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203)

@mp911de
Copy link
Member

mp911de commented Nov 29, 2022

Thanks a lot. This looks like a Spring Framework core issue as the proxy is being generated by org.springframework.orm.jpa.SharedEntityManagerCreator.

@mp911de mp911de changed the title Native Queries not working in JPA 3.0 native image Missing native hints for Hibernate Query proxy Nov 29, 2022
@mp911de mp911de changed the title Missing native hints for Hibernate Query proxy Missing native hints for Hibernate Native Query proxy Nov 29, 2022
@odrotbohm odrotbohm transferred this issue from spring-projects/spring-data-jpa Nov 29, 2022
@ahmedeewo
Copy link
Author

@mp911de you're welcome, thank you for your time and work, it's a great improvement

@ahmedBouchaibi
Copy link

ahmedBouchaibi commented Jan 2, 2023

@mp911de, can you help me please to be working?

I added this hint, but that is still not working.

        hints.reflection().registerType(NativeQueryImplementor.class, MemberCategory.values());
        hints.reflection().registerType(DomainQueryExecutionContext.class, MemberCategory.values());
        hints.reflection().registerType(ResultSetMappingResolutionContext.class, MemberCategory.values());
        hints.reflection().registerType(QueryImplementor.class, MemberCategory.values());
        hints.reflection().registerType(SelectionQuery.class, MemberCategory.values());
        hints.reflection().registerType(CommonQueryContract.class, MemberCategory.values());
        hints.reflection().registerType(NativeQueryImpl.class, MemberCategory.values());
        hints.reflection().registerType(SharedEntityManagerCreator.class,MemberCategory.values());

@NicklasWallgren
Copy link

@marcusdacoregio
Copy link

+1 for this, I am facing the same problem, the only difference is that I am not using native query.

com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.hibernate.query.hql.spi.SqmQueryImplementor, interface org.hibernate.query.sqm.internal.SqmInterpretationsKey$InterpretationsKeySource, interface org.hibernate.query.spi.DomainQueryExecutionContext, interface org.hibernate.query.SelectionQuery, interface org.hibernate.query.CommonQueryContract] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89) ~[na:na]
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.proxy.DynamicProxySupport.getProxyClass(DynamicProxySupport.java:171) ~[na:na]
        at java.base@17.0.5/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:47) ~[spring-data-jpa-native-3-1-2:na]
        at java.base@17.0.5/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037) ~[spring-data-jpa-native-3-1-2:na]
        at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:316) ~[na:na]

The error is thrown by:

@Bean
CommandLineRunner commandLineRunner(UserRepository userRepository) {
		return args -> {
			userRepository.save(new User("user@example.com"));
			Optional<User> user = userRepository.findByEmail("user@example.com"); // here
			user.ifPresent(System.out::println);
		};
}

The reproducible sample is here https://github.com/marcusdacoregio/query-hibernate-proxy-native-bug

@sdeleuze
Copy link
Contributor

@marcusdacoregio Your error is likely related to #31050 on should be fixed on latest snapshots.

@sdeleuze sdeleuze removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 18, 2023
@sdeleuze sdeleuze added this to the 6.0.12 milestone Aug 18, 2023
sdeleuze added a commit to sdeleuze/spring-aot-smoke-tests that referenced this issue Aug 18, 2023
wilkinsona pushed a commit to spring-projects/spring-aot-smoke-tests that referenced this issue Sep 21, 2023
wilkinsona added a commit to spring-projects/spring-aot-smoke-tests that referenced this issue Sep 21, 2023
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

7 participants