Atomikos Forum |
|
Hi, Guy.
Here I am facing a general programming issue. I am using Spring, JPA, Hibernate and Atomikos, and I am trying to do my own exception mapping. But once I get the Spring exception during a database-related JTA transaction branch commit, I can get the underlying JPA exception, but from there on, I cannot get the underlying Hibernate, and the further underlying SQL exception. I guess Hibernate's JPA implementation does not take care to properly chain exceptions. Any workaround you can think of using Atomikos? Thanks for your reply! I will also later on post this to a Hibernate forum.
Hi, Guy, here's the stack trace. On closer look, it seems that Atomikos JTA is throwing javax.transaction.RollbackException. I am wondering if I define Spring advice to run before that happens (if it is possible), will Atomikos implementation a) still rollback transaction based on the exception the exception, which will now be more specific; and b) allow the exception to propagate to my code so I can actually get the JPA/Hibernate-specific exception?
[WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: 23505 [ERROR] JDBCExceptionReporter - Batch entry 0 insert into js_network_connection (date_created, is_friend, requestor_id, responder_id, status, version, id) value s ('2010-09-25 -04:00:00', '1', '1', '2', '5', '0', '44') was aborted. Call get NextException to see the cause. [WARN] JDBCExceptionReporter - SQL Error: 0, SQLState: 23505 [ERROR] JDBCExceptionReporter - ERROR: duplicate key value violates unique const raint "js_network_connection_unique" [ERROR] AbstractFlushingEventListener - Could not synchronize database state wit h session <org.hibernate.exception.ConstraintViolationException: Could not execu te JDBC batch update>org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java :66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114 ) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109 ) at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.jav a:244) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntity Persister.java:2395) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntity Persister.java:2858) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Abst ractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventL istener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntit yManagerImpl.java:1001) at com.atomikos.icatch.jta.Sync2Sync.beforeCompletion(Sync2Sync.java:73) at com.atomikos.icatch.imp.TransactionStateHandler.commit(TransactionStateHandl er.java:253) at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactio nImp.java:511) at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp .java:138) at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:298) at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.j ava:612) at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:16 8) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransa ctionManager.java:1009) at org.springframework.transaction.support.AbstractPlatformTransactionManager.p rocessCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.c ommit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitT ransactionAfterReturning(TransactionAspectSupport.java:375) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:202) at $Proxy60.batchAddFriendRequest(Unknown Source) at com.tasktide.js.service.JobSeekerServiceWrapperImpl.batchAddFriendRequest(Jo bSeekerServiceWrapperImpl.java:220) at com.tasktide.js.action.network.AddFriendsAction.execute(AddFriendsAction.jav a:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionIn vocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActi onInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(D efaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(Validati onInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.do Intercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(Con versionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(St aticParametersInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectI nterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterce ptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInt erceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDr ivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(S copedModelDrivenInterceptor.java:130) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(Debu ggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingIn terceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareIn terceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nIntercepto r.java:165) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletCon figInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasIntercep tor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(Ex ceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.jav a:395) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterIn ternal(OpenEntityManagerInViewFilter.java:113) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestF ilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja va:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127 ) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102 ) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java :109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http 11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into js_network_c onnection (date_created, is_friend, requestor_id, responder_id, status, version, id) values ('2010-09-25 -04:00:00', '1', '1', '2', '5', '0', '44') was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(A bstractJdbc2Statement.java:2569) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.ja va:1796) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statem ent.java:2708) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.inv oke(AbstractJdbc23PooledConnection.java:455) at $Proxy59.executeBatch(Unknown Source) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 99 more [INFO] atomikos - atomikos connection proxy for Pooled connection wrapping physi cal connection org.postgresql.jdbc4.Jdbc4Connection@17bf9b45: isClosed()... [INFO] atomikos - atomikos connection proxy for Pooled connection wrapping physi cal connection org.postgresql.jdbc4.Jdbc4Connection@17bf9b45: calling getWarning s... [INFO] atomikos - atomikos connection proxy for Pooled connection wrapping physi cal connection org.postgresql.jdbc4.Jdbc4Connection@17bf9b45: calling clearWarni ngs... [INFO] atomikos - atomikos connection proxy for Pooled connection wrapping physi cal connection org.postgresql.jdbc4.Jdbc4Connection@17bf9b45: close()... [INFO] atomikos - XAResource.end ( 636F6D2E61746F6D696B6F732E737072696E672E6A646 2632E746D30303030353030323935:636F6D2E61746F6D696B6F732E737072696E672E6A6462632E 746D35 , XAResource.TMSUCCESS ) on resource postgres represented by XAResource i nstance org.postgresql.xa.PGXAConnection@56c492c8 [INFO] atomikos - setRollbackOnly() called for transaction com.atomikos.spring.j dbc.tm0000500295 [WARN] atomikos - Unexpected error in beforeCompletion: javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolat ionException: Could not execute JDBC batch update at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImp l.java:1179) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImp l.java:1112) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntit yManagerImpl.java:1008) at com.atomikos.icatch.jta.Sync2Sync.beforeCompletion(Sync2Sync.java:73) at com.atomikos.icatch.imp.TransactionStateHandler.commit(TransactionStateHandl er.java:253) at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactio nImp.java:511) at com.atomikos.icatch.imp.CompositeTerminatorImp.commit(CompositeTerminatorImp .java:138) at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:298) at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.j ava:612) at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:16 8) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransa ctionManager.java:1009) at org.springframework.transaction.support.AbstractPlatformTransactionManager.p rocessCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.c ommit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitT ransactionAfterReturning(TransactionAspectSupport.java:375) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:202) at $Proxy60.batchAddFriendRequest(Unknown Source) at com.tasktide.js.service.JobSeekerServiceWrapperImpl.batchAddFriendRequest(Jo bSeekerServiceWrapperImpl.java:220) at com.tasktide.js.action.network.AddFriendsAction.execute(AddFriendsAction.jav a:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionIn vocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActi onInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(D efaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(Validati onInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.do Intercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(Con versionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(St aticParametersInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectI nterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterce ptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInt erceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDr ivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(S copedModelDrivenInterceptor.java:130) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(Debu ggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingIn terceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareIn terceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nIntercepto r.java:165) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletCon figInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasIntercep tor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(Ex ceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.jav a:395) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterIn ternal(OpenEntityManagerInViewFilter.java:113) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestF ilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja va:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127 ) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102 ) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java :109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http 11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) Caused by: org.hibernate.exception.ConstraintViolationException: Could not execu te JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java :66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114 ) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109 ) at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.jav a:244) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntity Persister.java:2395) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntity Persister.java:2858) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(Abst ractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventL istener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375) at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntit yManagerImpl.java:1001) ... 85 more Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into js_network_c onnection (date_created, is_friend, requestor_id, responder_id, status, version, id) values ('2010-09-25 -04:00:00', '1', '1', '2', '5', '0', '44') was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(A bstractJdbc2Statement.java:2569) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.ja va:1796) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statem ent.java:2708) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.postgresql.ds.jdbc23.AbstractJdbc23PooledConnection$StatementHandler.inv oke(AbstractJdbc23PooledConnection.java:455) at $Proxy59.executeBatch(Unknown Source) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 99 more [INFO] atomikos - XAResource.rollback ( 636F6D2E61746F6D696B6F732E737072696E672E 6A6462632E746D30303030353030323935:636F6D2E61746F6D696B6F732E737072696E672E6A646 2632E746D35 ) on resource postgres represented by XAResource instance org.postgr esql.xa.PGXAConnection@56c492c8 [INFO] atomikos - XAResource.end ( 636F6D2E61746F6D696B6F732E737072696E672E6A646 2632E746D30303030353030323935:636F6D2E61746F6D696B6F732E737072696E672E6A6462632E 746D36 , XAResource.TMSUCCESS ) on resource activemq represented by XAResource i nstance org.apache.activemq.TransactionContext@53c36f46 [INFO] atomikos - XAResource.rollback ( 636F6D2E61746F6D696B6F732E737072696E672E 6A6462632E746D30303030353030323935:636F6D2E61746F6D696B6F732E737072696E672E6A646 2632E746D36 ) on resource activemq represented by XAResource instance org.apache .activemq.TransactionContext@53c36f46 [INFO] atomikos - afterCompletion ( STATUS_ROLLEDBACK ) called on Synchronizati on: org.hibernate.ejb.AbstractEntityManagerImpl$1@66a9aa83 [INFO] atomikos - afterCompletion ( STATUS_ROLLEDBACK ) called on Synchronizati on: org.hibernate.transaction.CacheSynchronization [INFO] atomikos - atomikos xa session proxy for resource activemq: closing sessi on atomikos xa session proxy for resource activemq - is terminated ? true [INFO] atomikos - atomikos xa session proxy for resource activemq: calling close on JMS driver session... [INFO] atomikos - atomikos connection proxy for resource activemq: close()... javax.transaction.RollbackException: The transaction was set to rollback only at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:312) at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.j ava:612) at com.atomikos.icatch.jta.UserTransactionImp.commit(UserTransactionImp.java:16 8) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransa ctionManager.java:1009) at org.springframework.transaction.support.AbstractPlatformTransactionManager.p rocessCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.c ommit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitT ransactionAfterReturning(TransactionAspectSupport.java:375) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(Tr ansactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflect iveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopPro xy.java:202) at $Proxy60.batchAddFriendRequest(Unknown Source) at com.tasktide.js.service.JobSeekerServiceWrapperImpl.batchAddFriendRequest(Jo bSeekerServiceWrapperImpl.java:220) at com.tasktide.js.action.network.AddFriendsAction.execute(AddFriendsAction.jav a:44) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39 ) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionIn vocation.java:441) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActi onInvocation.java:280) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:243) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(D efaultWorkflowInterceptor.java:165) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(Validati onInterceptor.java:252) at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.do Intercept(AnnotationValidationInterceptor.java:68) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(Con versionErrorInterceptor.java:122) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(Parame tersInterceptor.java:195) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(St aticParametersInterceptor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectI nterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterce ptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInt erceptor.java:235) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDr ivenInterceptor.java:89) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(S copedModelDrivenInterceptor.java:130) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(Debu ggingInterceptor.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingIn terceptor.java:126) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareIn terceptor.java:138) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(Method FilterInterceptor.java:87) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nIntercepto r.java:165) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletCon figInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasIntercep tor.java:179) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(Ex ceptionMappingInterceptor.java:176) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocati on.java:237) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.jav a:395) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterIn ternal(OpenEntityManagerInViewFilter.java:113) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestF ilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application FilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh ain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja va:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja va:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127 ) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102 ) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java :109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http 11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:619) [INFO] JobSeekerServiceWrapperImpl - Causing exception: javax.transaction.Rollba ckException Ending JS test:
I see,
The exception happens in Hibernate's flushing before commit, triggered by the Spring transaction manager proxy (at commit time) - after your Hibernate code has executed. That is why you don't see it. As to what the best solution is: I need to think about that. ..
Hi, Guy, I am sorry to bother you, could you please inform when the next release is going to be?
At issue, generally, is the ability of developers to avoid issuing expensive SQL queries to check for duplicates of constraint violations in their data model; and instead we can rely on exception translation to get a meaningful idea of what happened - it is just so much cheaper in terms of resources to throw an exception than to make an SQL query to the disk.
Hi, guy. I am sorry, it turns out the javax.transaction.RollbackException does not have the contructor to add the causing Throwable. For some weird reason it does not. But - I still somehow solved the issue I was having by introducing a Spring aspect to run in between the aspect doing the transaction begin commit, with the following code:
package apackage; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.RollbackException; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.springframework.core.annotation.Order; @Aspect @Order(value = 201) public class ExceptionTranslationAspect { @PersistenceContext(name = "acontext") private EntityManager entityManager; // "bean(jobSeekerServiceInner)" @Around("@annotation(com.tasktide.annotation.ExceptionTranslationRequired)") // @Transactional(value = "jta", propagation = Propagation.SUPPORTS, // isolation = Isolation.DEFAULT) public Object handlePersistenceException(final ProceedingJoinPoint pjp) { System.out.println("Advising bean firing."); Object retVal = null; try { retVal = pjp.proceed(); this.entityManager.flush(); } catch (final Throwable th) { // System.out.println(th.getMessage()); // System.out.println(th.getCause().getMessage()); throw new RollbackException(th.getMessage(), th); } System.out.println("Advising bean finished firing."); return retVal; } public void setEntityManager(final EntityManager entityManager) { this.entityManager = entityManager; } } The most surprising thing about it is that it seems to work! Could you comment, please?
Guy, that solution does not work if ActiveMQ fails; it only works in database fails.
So... with javax.transaction.RollbackException not working properly because it does not have chaining constructor, I don't really see any other way for you people to achieve exception chaining except by subclassing javax.transaction.RollbackException and having that subclass thrown in your code. This way it should not break pre-existing code, and new code could take clumsy advantage of exception chaining? Am I sounding coherent?
Hi,
An interesting point about the exception you are seeing: this one is caused by a Synchronisation.beforeCompletion() callback. In general, there are many of those in one transaction, and a failure/exception leads to rollback but only after all other synchronisations are called. The bottom line: this is an exception that does not simply propagate up into the call stack. There can even be many of them - one for each Synchronisation - leading to the same final rollback. So: I think it is fair to log this as a warning and NOT include it in the RollbackException as the one and only cause. Your thoughts?
My thoughts: you should make a conscious decision to provide the first exception that will result in rollback as the chained cause for your icatch RollbackException.
The way I understood the Synchronization implementation from your words is that there are several Synchronizations one after another possible. The reason I think your product would benefit from it is due to the following use case: I am trying to save an object to a database, but the table already contains a row fulfilling some unique constraint (primary key or some other one.) I can either issue an SQL query to check before saving, or I can rely on the exception thrown. If I rely on the exception thrown, I save 50% of database traffic. Therefore, if Atomikos properly chains exceptions, you can claim that with your product this significant resource saving is possible. Additionally, it would be beneficial if you also provided a set of exception-mapping classes that, for instance, mapped PostgreSQL error codes to appropriate error conditions. Oracle, DB2, MS SQL Server could also be implemented. It could be a competitive advantage for your product by enabling a better programming model for JTA transactions. I am not sure what the demand for such programming model would be, but I am finding this a significant programming issue with my application. I don't want to use a full-blown app server, and I do not know whether, say, JBoss JTA manager chains exceptions so I can wind down to the root cause, but if it does not, for example, I obviously am STUCK with issuing 2 SQL queries instead of 1. In this case, if some other vendor enables me to program to the exception, it would create a better scalability scenario for me. |