- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
假设我有实体 Account
:
@Entity(name = "ACCOUNT")
@EntityListeners(Listener.class)
public class AccountEntity {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
@Column(name = "ACCOUNT_ID")
Long id;
@Column(name = "USERNAME")
String username;
@Column(name = "PASSWORD")
String password;
<getters and setters... />
将存储有关数据库更改信息的实体历史记录:
@Entity(name="OPERATION_HISTORY")
public class OperationHistoryEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name="OPERATION_HISTORY_ID")
Long id;
@Column(name = "ENTITY_NAME")
String entityName;
@Column(name = "RECORD_ID")
Long recordId;
@Column(name = "OPERATION")
String operation;
@Column(name = "CREATION_DATE")
Timestamp creationDate;
@Column(name = "UPDATE_DATE")
Timestamp updateDate;
@Column(name = "REMOVE_DATE")
Timestamp removeDate;
<getters and setters... />
将存储此信息的服务:
@Service
public class OperationHistoryService {
@PersistenceContext
EntityManager entityManager;
@Autowired
OperationHistoryRepository operationHistoryRepository;
@Transactional
public void addOperation(OperationHistoryEntity operationHistoryEntity) {
entityManager.persist(operationHistoryEntity);
}
}
最后是听众:
@Component
public class Listener {
@Autowired
OperationHistoryService operationHistoryService;
@PostPersist
public void postPersist(Object obj) {
<variables... />
OperationHistoryEntity operationHistoryEntity = new OperationHistoryEntity();
operationHistoryEntity.setEntityName(entityName);
operationHistoryEntity.setRecordId(recordId);
operationHistoryEntity.setOperation(operation);
operationHistoryEntity.setCreationDate(creationDate);
operationHistoryEntity.setUpdateDate(creationDate);
operationHistoryEntity.setRemoveDate(creationDate);
operationHistoryService.addOperation(operationHistoryEntity);
}
当我运行它时出现错误:
java.lang.Exception: exception just for purpose of providing stack trace
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.markRollbackOnly(JdbcResourceLocalTransactionCoordinatorImpl.java:265)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:156)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:483)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:290)
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:655)
at com.service.AccountService$$EnhancerBySpringCGLIB$$f91573cb.addAccount(<generated>)
at com.rest.AuthenticationController.createNewAccount(AuthenticationController.java:92)
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:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at com.jwtimpl.security.AuthenticationTokenFilter.doFilter(AuthenticationTokenFilter.java:47)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at com.jwtimpl.CorsFilter.doFilter(CorsFilter.java:22)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
来自休息服务的错误信息:
Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction
是否可以在postPersist方法中保存这个operationHistoryEntity对象?我想我可以只用@EntityListeners 注释实体,然后将数据库中有关新的、修改的或删除的记录的信息保存到 OperationHistory 表中。
最佳答案
我得到了同样的错误信息:java.lang.Exception: exception just for purpose of providing stack trace
。
发生此错误是因为当 hibernate 尝试使用事务将实体保存在数据库中时会产生异常。在我的例子中是因为我将注释 @NotNull
放在一个属性中并且我试图用 null 保存实体。
要了解您发生了什么,请在保存方法周围使用 try-catch 捕获 java.lang.Exception
并查看异常的 detailMessage
。
关于java - 如何在 hibernate postPersist 监听器中持久化实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39370147/
我是Hibernate的新手。当我保存特定实体时,它将从现有实体中重写数据。 我将ID用作自动生成,如下所示: @Id @GeneratedValue(strategy=GenerationType.
我正在尝试以连续模式使用CouchDB更改通知API,所以我想发送此消息 _changes?feed = continuous?include_docs = true作为GET请求到达我的CouchD
我有 XMPP 服务器(openfire)和一堆客户端(spark),分为几个组(部门)。我正在寻找能够将它们留在 session 室中的能力。我的意思是 Skype 具有的类似功能;当用户关闭带有群
我发布这个问题是为了看看我是否正确理解 Azure Functions 中的并行性,特别是 Durable Functions。 最近使用 az cli 在 Azure Functions 中添加了设
我在 Dev Env 上有一个 AKS 集群,上面运行着一些容器。我还启用了 Azure Log Analytics。但我可以看到正在运行的当前容器的日志,而不是已被终止或停止的旧容器的日志。 我想知
在 Akka 中,当一个 actor 在处理消息时死亡(在 onReceive(...) { ... } 内),该消息就会丢失。有没有办法保证无损?有一种配置 Akka 在将消息发送到 onRecei
我试图让 selectOneMany 取得有限的成功。 我有以下数据库模型 User email Text verkey Text Maybe verified Bool password T
我需要使用持久性(Yesod)从键列表中获取实体列表 假设我有一个 Model 及其相应的 ModelId。我身边有: keys :: [ModelId] 我需要得到 models :: [Model
我有一个使用 GWT、请求工厂和地点/Activity 构建的网络应用程序。我很好奇我使用的历史 token 是否持久。该任务基本上就是让 URL 定义我的网络应用程序的确切位置(读作“文件/文件夹结
我正在寻找一种 jQuery 方法来在刷新页面时使页面元素持久保留在用户屏幕上。当我刷新页面并且丢失 jQuery 页面中的内容时,它会发生变化。 我需要页面持久。如何刷新页面并保持元素不刷新(持久)
当我尝试使用 gcc 编译带有 -fopenmp 标志的 C 代码时,我已经持续收到此错误超过 6 小时了。 错误:控制谓词无效 for ( int i = 0; i #include #ifde
我有带有验证注释的实体,例如@NotNull。我不知道如何防止容器管理的事务在批量持久操作中出现 ConstraintViolationException 的情况下回滚,例如: public void
这是我的代码: http://jsfiddle.net/KCb5z/8/embedded/result/ http://jsfiddle.net/KCb5z/8/ $(function () {
我正在与服务器通信,理想情况下,我希望输入流和输出流始终处于运行状态。我收到未经请求的响应,因此我必须始终准备好接收输入流上的数据。 在我进一步深入之前,我应该说我建立的任何连接都必须能够支持 SSL
我正在寻找一种正确扩展 Azure Functions 的方法,但遇到了问题。 我有一组 IoT 设备,通过 HTTP 向 Azure 发送数据(为此,有一组自动扩展的 Azure Functions
1.临时态(瞬时态) 不存在于session中,也不存在于数据库中的数据,被称为临时态。 比如:刚刚使用new关键字创建出的对象。 2.持久态 存在于session中,事务还未提交,提交之后
我在 Kohana v2 中使用数据库 session 驱动程序。为了使 session 持久化,Kohana 创建了一个 token cookie。这个 cookie 使用了我想的 cookie 配
有谁知道是否有办法使用 PyWinrm 打开一个持久的 PowerShell session ,该 session 保持状态并且可以多次调用?我正在尝试执行以下操作: #!/bin/python im
在运行的Elasticsearch集群中,配置文件中的index.number_of_replicas设置为1。 我可以通过运行以下命令在运行的集群上将其更新为2 # curl -XPUT "http
我在“这么长的帖子必须意味着大量的代码和配置”部分下一对一地使用指南代码。 http://blog.springsource.com/2006/08/07/using-jpa-in-spring-wi
我是一名优秀的程序员,十分优秀!