In Java 17 and spring mvc application, with xml configuration files, I called org.hibernate.query.Query in aop, getting the issue: jdk.proxy2.$Proxy155 is in module jdk.proxy2 of loader 'app'; org.hibernate.query.Query is in unnamed module of loader 'app'

Caused by: java.lang.ClassCastException: class jdk.proxy2.$Proxy155 cannot be cast to class org.hibernate.query.Query (jdk.proxy2.$Proxy155 is in module jdk.proxy2 of loader 'app'; org.hibernate.query.Query is in unnamed module of loader 'app') at org.hx.resequence.batch.job.utils.HibernateQueryLoggingAspect.logSqlAndParameters(HibernateQueryLoggingAspect.java:22) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) at org.hx.resequence.batch.job.utils.HibernateExceptionLoggingAspect.logHibernateException(HibernateExceptionLoggingAspect.java:32) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Similar issue also happens when I defined an interceptor, but it cannot have the correct type, log as below: Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'Intercerptor' is expected to be of type 'org.HibernateSQLInterceptor' but was actually of type 'jdk.proxy2.$Proxy197' at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1401) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:710) ... 239 common frames omitted

Comment From: johnxu2013

I searched web, and it said this is because JEP 396, the modules are different in java 17. But how to resolve it in aop?

Comment From: sdeleuze

Looks like potentially a question StackOverfow, if that's the case please close this issue and ask it on SO. If you think that's a genuine bug, please provide a self-contained reproducer (link to a repository or attached archive), and please make sure you provide the documentation to reproduce step by step.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.