- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
每当我尝试在实体上使用 @PreUpdate 注释时,都会收到 stackoverflow 异常,该实体使用嵌入式可审计实体和 @EntityListeners。
在我的实体中,我尝试通过服务获取用户数据,以便更新实体上的 CreateBy/LastUpdateBy 字段。我不能简单地将字符串放入其中,我需要对用户本身的引用。
我已经尝试过将实体管理器注入(inject) AuditListener 并手动刷新它的方法,但它无法正常工作。另外,我尝试在 spring 上下文中传递用户数据而不是使用服务,但由于它保留静态值,所以它对我没有用处。我需要以某种方式获取 AuditListener 中的 User 实体,而不进入无限循环。
有什么想法吗?
这是堆栈跟踪:
2019-01-04 15:45:52 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
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:671)
at com.app.server.repositories.impl.UserRepositoryImpl$$EnhancerBySpringCGLIB$$d072e6d0.findByUsername(<generated>)
at com.app.server.services.impl.UserServiceImpl.findUserByUsername(UserServiceImpl.java:131)
at com.app.server.services.impl.UserServiceImpl$$FastClassBySpringCGLIB$$852b5ce2.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:667)
at com.app.server.services.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$80381f41.findUserByUsername(<generated>)
at com.app.server.defautmodel.audit.UserTimeAuditListener.setUpdatedOn(UserTimeAuditListener.java:37)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.jpa.event.internal.ListenerCallback.performCallback(ListenerCallback.java:35)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.callback(CallbackRegistryImpl.java:97)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.preUpdate(CallbackRegistryImpl.java:71)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.invokeInterceptor(DefaultFlushEntityEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:332)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:283)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:235)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:94)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1415)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1501)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
at org.hibernate.query.Query.getResultList(Query.java:135)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74)
at com.app.server.repositories.impl.UserRepositoryImpl.findByUsername(UserRepositoryImpl.java:40)
at com.app.server.repositories.impl.UserRepositoryImpl$$FastClassBySpringCGLIB$$46c3b507.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
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:671)
at com.app.server.repositories.impl.UserRepositoryImpl$$EnhancerBySpringCGLIB$$d072e6d0.findByUsername(<generated>)
at com.app.server.services.impl.UserServiceImpl.findUserByUsername(UserServiceImpl.java:131)
at com.app.server.services.impl.UserServiceImpl$$FastClassBySpringCGLIB$$852b5ce2.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:667)
at com.app.server.services.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$80381f41.findUserByUsername(<generated>)
at com.app.server.defautmodel.audit.UserTimeAuditListener.setUpdatedOn(UserTimeAuditListener.java:37)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.jpa.event.internal.ListenerCallback.performCallback(ListenerCallback.java:35)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.callback(CallbackRegistryImpl.java:97)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.preUpdate(CallbackRegistryImpl.java:71)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.invokeInterceptor(DefaultFlushEntityEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:332)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:283)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:235)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:94)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1415)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1501)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
at org.hibernate.query.Query.getResultList(Query.java:135)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74)
at com.app.server.repositories.impl.UserRepositoryImpl.findByUsername(UserRepositoryImpl.java:40)
at com.app.server.repositories.impl.UserRepositoryImpl$$FastClassBySpringCGLIB$$46c3b507.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
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:671)
at com.app.server.repositories.impl.UserRepositoryImpl$$EnhancerBySpringCGLIB$$d072e6d0.findByUsername(<generated>)
at com.app.server.services.impl.UserServiceImpl.findUserByUsername(UserServiceImpl.java:131)
at com.app.server.services.impl.UserServiceImpl$$FastClassBySpringCGLIB$$852b5ce2.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:667)
at com.app.server.services.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$80381f41.findUserByUsername(<generated>)
at com.app.server.defautmodel.audit.UserTimeAuditListener.setUpdatedOn(UserTimeAuditListener.java:37)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.jpa.event.internal.ListenerCallback.performCallback(ListenerCallback.java:35)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.callback(CallbackRegistryImpl.java:97)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.preUpdate(CallbackRegistryImpl.java:71)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.invokeInterceptor(DefaultFlushEntityEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:332)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:283)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:235)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:94)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1415)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1501)
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
at org.hibernate.query.Query.getResultList(Query.java:135)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74)
at com.app.server.repositories.impl.UserRepositoryImpl.findByUsername(UserRepositoryImpl.java:40)
at com.app.server.repositories.impl.UserRepositoryImpl$$FastClassBySpringCGLIB$$46c3b507.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
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:671)
at com.app.server.repositories.impl.UserRepositoryImpl$$EnhancerBySpringCGLIB$$d072e6d0.findByUsername(<generated>)
at com.app.server.services.impl.UserServiceImpl.findUserByUsername(UserServiceImpl.java:131)
at com.app.server.services.impl.UserServiceImpl$$FastClassBySpringCGLIB$$852b5ce2.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:667)
at com.app.server.services.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$80381f41.findUserByUsername(<generated>)
at com.app.server.defautmodel.audit.UserTimeAuditListener.setUpdatedOn(UserTimeAuditListener.java:37)
at sun.reflect.GeneratedMethodAccessor177.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.hibernate.jpa.event.internal.ListenerCallback.performCallback(ListenerCallback.java:35)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.callback(CallbackRegistryImpl.java:97)
at org.hibernate.jpa.event.internal.CallbackRegistryImpl.preUpdate(CallbackRegistryImpl.java:71)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.invokeInterceptor(DefaultFlushEntityEventListener.java:350)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:332)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:283)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:235)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:94)
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:44)
最佳答案
默认情况下,所有事务都是读/写
,并且由于您使用@PreUpdate
,由于读/写
事务上的FlushMode
,因此所有事务都将始终触发它。在您的情况下,如果您想在只获取需要为事务指定的数据(至少为readOnly
)的情况下绕过@PreUpdate
,这将在FlushMode.NEVER
中创建hiberbate session ,因此@PreUpdate
将不会被触发。为了更加安全,以防您的事务嵌入到 pervios 事务中,以便它将继承其属性,您可以使用 Propagation.REQUIRES_NEW
这将暂停以前的事务执行,但要小心它,因为这可能会导致大型应用程序中的性能问题
关于java - @PreUpdate 上的 Stackoverflow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54041338/
使用 htaccess 我能够隐藏文件扩展名,使其成为/home 而不是/home.html。但是,对于主页,我想完全隐藏文件名,例如 stackoverflow.com,而不是 stackoverf
我试图在关闭子窗体时关闭我的主(父)窗体。然而,这给了我一个 StackOverflow 异常。 但是,如果我在 FormClosed 事件上调用 _child.Dispose,它会按预期工作。我应该
我在 IDEA 中使用 Gradle 并得到以下输出。 * What went wrong: A problem occurred evaluating script. > java.lang.Sta
我是一个 java 新手,并且在 StackOverflow 错误/在类之间访问文件的能力方面遇到了一个非常令人困惑的问题。我知道根本原因可能是我进行了一些递归调用,但修复它的语法却让我无法理解。我认
我需要编写一个程序来生成一些随机数,而不让两个数字落在某个范围内。不幸的是,我需要在学校做这件事,而我在计算机上唯一可以使用的语言是 Java(否则我会用 C++ 来做)。我对 Java 知之甚少,我
尝试设置一个 Person 类 我在尝试将信息封装在类中以使其不会被意外更改时遇到了问题。除了当我尝试使用 setter/getters 进行封装时,该类工作得非常好。我认为问题是这些方法最终会互相循
使用 scala,我已将大约 100000 个节点添加到链表中。当我使用函数 length 时,例如 mylist.length。我收到“java.lang.StackOverflowError”错误
我正在开发一个学校项目,该项目必须有 3 个带 1 个指针的快速排序、3 个带 2 个指针和 2 个堆的快速排序。 到目前为止,我已经编写了快速排序和堆之一。我遇到的问题是快速排序在小情况下工作正常,
我正在制作一个程序,它生成列表的所有子集,然后排列所有这些子集。我有一个生成子集的方法和一个生成排列的方法。但是,它们不能一起工作,即当我排列子集时,我没有得到子集的所有排列,并且出现 StackOv
我有以下函数,它应该产生笛卡尔平面中的所有坐标,我可以在n步中从原点到达: 原点是“位置”,步数是“强度”,它是一个 1-10 的整数。但是,我不断收到 stackoverflow 错误。每次我调用它
当我尝试使用 scala lib(使用 re2)匹配上述正则表达式时,代码进入以下路径并超时 1 分钟: 正则表达式: (([a-z0-9!#$%&'*+?^_`{|}~-]+(?:.[a-z0-9!
我正在开发一个运输 map 项目。我为该位置创建了一个名为 Chart 的对象和一个名为 Pos 的对象。我无法开始工作的是,当我从文本文件读取图表以正确创建对象 Pos 时,因为这就是失败的地方。
public class SortAnimal { public static Comparator getAnimalTagComparator() { return
我因使用以下泛型而收到 StackOverflowError: 积分: package me.expdev.gkitpvp; /* * Project created by ExpDev */ i
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我为一些命题逻辑表达式编写了一个javaCC解析器。表达式可能会很长,有 30k 个字符。 当我解析如此大的表达式时,出现堆栈溢出异常。 是否有一些虚拟机参数决定堆栈大小? 或者在这种情况下你会怎么做
这个问题已经有答案了: What is a StackOverflowError? (15 个回答) 已关闭 8 年前。 最高数字double可以代表极高,我想。尽管下面的代码会抛出异常。这实际上是我
我正在为我的 API 构建一个 SDK,其中有两个模块,分别是 A 类和 B 类。 public class A{ public final B = new B(); public f
执行此递归时,我收到堆栈溢出错误。有一个模式,它第一次说: at MazeGui.move(MazeGui.java:79) which is line if(rigting.goal == true
我编写的这段代码在达到一定的输入大小之前效果很好。如果输入太大,我会收到“java.lang.StackOverflowError”。我已经阅读了 stackoverflow 上有关此主题的其他一些条
我是一名优秀的程序员,十分优秀!