开发者

getting java.lang.reflect.UndeclaredThrowableException over hibernate orm

I have HibernateInterceptor for a method which takes the hibernate ORM as argument

I am getting java.lang.reflect.UndeclaredThrowableException when the method is invoked. The cause is shown as

Caused by: java.lang.NoSuchMethodException: $Proxy25.sav开发者_开发技巧eData(com.test.orm.Employee$$EnhancerByCGLIB$$bcc67d7, java.util.HashMap)

The saveData(com.test.orm.Employee, java.util.HashMap) is my method.

Following is my aspect code for interceptor

 @Around(“@target (com.test.HibernateInterceptorRequired)”)
    public Object interceptCall(ProceedingJoinPoint joinPoint) throws Throwable {
    ProxyFactory proxyFactory = new ProxyFactory(joinPoint.getTarget());
    proxyFactory.addAdvice(hibernateInterceptor);

    Class [] classArray = new Class[joinPoint.getArgs().length];
    for (int i = 0; i < classArray.length; i++)
    classArray[i] = joinPoint.getArgs()[i].getClass();

    return
    proxyFactory
    .getProxy()
    .getClass()
    .getDeclaredMethod(joinPoint.getSignature().getName(), classArray)
    .invoke(proxyFactory.getProxy(), joinPoint.getArgs());
    }

Please help me to fix this.


I guess the problem is here:

classArray[i] = joinPoint.getArgs()[i].getClass(); 

You use classes of the actual parameters to build a method signature to look for, therefore you end up with signature such as $Proxy25.saveData(com.test.orm.Employee$$EnhancerByCGLIB$$bcc67d7, java.util.HashMap) that doesn't match the real signature.

Perhaps you need to do something with ProceedingJoinPoint.getSignature() instead, something like this:

Method m = ((MethodSignature) pjp.getSignature()).getMethod();
return m.invoke(proxyFactory.getProxy(), joinPoint.getArgs()); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜