这是 Spring 4.1.9.RELEASE、Spring-Data 1.11.4.RELEASE、Javers 1.6.0 和 spring 集成
因此,使用 Spring with @JaversAuditable
,我发现如果在我尝试插入时处理异常(例如重复键异常),JaversTransactionalDecorator
仍然会继续并尝试生成提交。
但是,由于插入失败,我的实体没有 ID,因此 Javers 最终会引发异常(见下文)。逐步调试,我发现我最终org.springframework.aop.aspectjAspectJAfterAdvice.invoke()
进入了 finally 块。然后它invokeAdviceMethod(JoinPointMatch,null,null)
跟注,第三个null
是 a 的位置Throwable
。
根据http://docs.spring.io/spring/docs/4.1.9.RELEASE/spring-framework-reference/html/aop.html,@After
建议将作为最终运行,无论该方法是否正常存在或具有例外。因此,听起来 Javers 需要能够检测是否引发了异常,或者使用不同的 Advice,例如@AfterReturning
,可能使用单独的@AfterThrowing
. 我试图在当前找出@After
Javers ( org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.commitAdvice(JoinPoint pjp)
) 如何检测是否已抛出异常/可抛出对象,但我似乎在文档中找不到任何关于此的内容。
那么,这是 Javers 已经拥有的东西,但由于某种原因它没有正确地处理抛出的 SQL 异常,或者在哪里可以找到一些关于在@After
建议中检测到抛出的异常/可抛出异常的信息,以便我可以进入并为此提供修复?
抱歉,可能不太有条理,我在这里比正常时间晚了几个小时。
Caused by: org.javers.common.exception.JaversException: ENTITY_INSTANCE_WITH_NULL_ID Found Entity instance of class 'com.findology.api.model.publisher.Publisher' with null id
at org.javers.core.metamodel.type.EntityType.getIdOf(EntityType.java:96)
at org.javers.core.metamodel.object.InstanceId.createFromInstance(InstanceId.java:28)
at org.javers.core.metamodel.object.GlobalIdFactory.createId(GlobalIdFactory.java:47)
at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:24)
at org.javers.core.graph.LiveCdoFactory.create(LiveCdoFactory.java:9)
at org.javers.core.graph.EdgeBuilder.asCdo(EdgeBuilder.java:39)
at org.javers.core.graph.ObjectGraphBuilder.buildGraph(ObjectGraphBuilder.java:45)
at org.javers.core.graph.LiveGraphFactory.createLiveGraph(LiveGraphFactory.java:39)
at org.javers.core.commit.CommitFactory.create(CommitFactory.java:76)
at org.javers.core.JaversCore.commit(JaversCore.java:70)
at org.javers.spring.jpa.JaversTransactionalDecorator.commit(JaversTransactionalDecorator.java:52)
at org.javers.spring.jpa.JaversTransactionalDecorator$$FastClassBySpringCGLIB$$acb40bd0.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:718)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at org.javers.spring.jpa.JaversTransactionalDecorator$$EnhancerBySpringCGLIB$$c6591394.commit(<generated>)
at org.javers.spring.auditable.aspect.JaversCommitAdvice.commitMethodArguments(JaversCommitAdvice.java:24)
at org.javers.spring.auditable.aspect.JaversAuditableRepositoryAspect.commitAdvice(JaversAuditableRepositoryAspect.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:603)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
at com.findology.api.dao.PublisherDao$$EnhancerBySpringCGLIB$$8ba00510.insert(<generated>)
at com.findology.api.controller.SimpleController.createPublisher(SimpleController.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:775)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:965)
... 74 common frames omitted