Below is a stack trace that I'm seeing on a new web service I wrote. The web
service should create a parent object (Trade) and several child objects
(CandidateAttachment). The actual exception I'm seeing is that the parent
object id doesn't exist, so the foreign key constraint is stopping the
attachments from being saved, which would make sense, except
1) I just created the parent
2) After the exception, the parent still exists (is committed), and of
course the child does not
3) This only happens intermittently
I'm polling a remote system to create these Trade and Candidate attachment
objects. At 10:15, I got this exception that I can't explain, and 10:30 it ran
successfully.
In my code, the web service method that RestEasy calls is not marked with
@CommitAfter. The web service function calls a method in WelliHornLogic called
createTrade that is annotated with CommitAfter. A ConstraintVilationException
is a runtime exception, so the failure should cause the entire transaction to
rollback, but that's not what I'm seeing happening.
I'm at a loss as to what I can check next. I'd prefer to fix the problem such
that the transaction commits correctly the first time. The actual method that
is in TradeLogic that creates these objects is called from the actual web
application and works as expected there. Failing that, I'd really like to
understand what is going on with transaction handling that an aborted
transaction gets partially committed.
Thanks in advance for any suggestions on what I should look at.
Tony
Here is the actual exception and it's root cause.
2018-02-06T10:15:14 http-apr-8080-exec-5 ERROR
com.starpoint.instihire.web.services.WebServicesModule.WelliHornWebService
Could not execute 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.engine.ActionQueue.executeActions(ActionQueue.java:268)
at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at
com.starpoint.instihire.api.dao.hibernate.Dao.store(Dao.java:44)
at
com.starpoint.instihire.api.dao.hibernate.AttachmentDaoImpl.storeAttachment(AttachmentDaoImpl.java:54)
at $AttachmentDao_e3b6d5997b201.storeAttachment(Unknown Source)
at
com.starpoint.instihire.api.business.AttachmentLogicImpl.storeAttachment(AttachmentLogicImpl.java:809)
at
com.starpoint.instihire.api.business.AttachmentLogicImpl.storeCandidateAttachment(AttachmentLogicImpl.java:387)
at
$AttachmentLogic_e3b6d5997ad05.storeCandidateAttachment(Unknown Source)
at
com.starpoint.instihire.api.business.TradeLogicImpl.createTrade(TradeLogicImpl.java:185)
at $TradeLogic_e3b6d5997acf1.createTrade(Unknown Source)
at
com.starpoint.instihire.api.business.WelliHornLogicImpl.createTrade(WelliHornLogicImpl.java:456)
at $WelliHornLogic_e3b6d5997b372.createTrade(Unknown Source)
at
com.starpoint.instihire.web.ws.WelliHornWebServiceImpl.createTrade(WelliHornWebServiceImpl.java:162)
at $WelliHornWebService_e3b6d5997c491.createTrade(Unknown
Source)
at
$WelliHornWebService_e3b6d5997c492.advised$createTrade_e3b6d5997c496(Unknown
Source)
at
$WelliHornWebService_e3b6d5997c492$Invocation_createTrade_e3b6d5997c495.proceedToAdvisedMethod(Unknown
Source)
at
org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:84)
at
com.starpoint.instihire.web.services.WebServicesModule$1.advise(WebServicesModule.java:64)
at
org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
at $WelliHornWebService_e3b6d5997c492.createTrade(Unknown
Source)
at $WelliHornWebService_e3b6d5997ace4.createTrade(Unknown
Source)
at sun.reflect.GeneratedMethodAccessor2536.invoke(Unknown
Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:272)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:229)
at
org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:216)
at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
at
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
at
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at
org.tynamo.resteasy.ResteasyRequestFilter.service(ResteasyRequestFilter.java:97)
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into
CandidateAttachment (attachmentName, createDate, CreateUserId, updateDate,
UpdateUserId, AgencyId, attachmentType, isDeleted, TradeId, attachmentId)
values ('redacted.doc', '2018-02-06 10:15:14.805000 -05:00:00', 1088,
'2018-02-06 10:15:14.805000 -05:00:00', 1088, 230, 'application/msword', 'N',
401734, 420468) was aborted. Call getNextException to see the cause.
at
org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2762)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1999)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:421)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2929)
at sun.reflect.GeneratedMethodAccessor329.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
net.bull.javamelody.JdbcWrapper.doExecute(JdbcWrapper.java:412)
at
net.bull.javamelody.JdbcWrapper$StatementInvocationHandler.invoke(JdbcWrapper.java:137)
at
net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:294)
at com.sun.proxy.$Proxy90.executeBatch(Unknown Source)
at
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 71 more
This exception was in turn caused by:
ERROR org.hibernate.util.JDBCExceptionReporter ERROR: insert or update on
table "candidateattachment" violates foreign key constraint
"fk_candidateattachment_trade" Detail: Key (tradeid)=(401734) is not present
in table "trade".