hapifhir / hapi-fhir

🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
http://hapifhir.io
Apache License 2.0
2.02k stars 1.32k forks source link

Expunge on a ValueSet Resource results in a forgeign key constraint exception #4305

Open PanayiotisCS opened 1 year ago

PanayiotisCS commented 1 year ago

Describe the bug

After deleting a record using the DELETE verb, we have attempted to $expunge the record, which resulted in a foreign key contraint exception.

Please see the stack trace attached.

To Reproduce Steps to reproduce the behavior: 1 Delete the resource curl --location --request DELETE 'http://localhost:8080/fhir/ValueSet/102'

2 Expunge the resource

curl --location --request POST 'http://localhost:8080/fhir/ValueSet/102/$expunge' \
--header 'Content-Type: application/json' \
--data-raw '{
  "resourceType": "Parameters",
  "parameter": [
    {
      "name": "expungeDeletedResources",
      "valueBoolean": true
    }
  ]
}'

Expected behavior Resource should be expunged from the database.

Actual behaviour Forgeign Key Constraint Exception is raised

Screenshots

biobankhapi-fhir-jpaserver-db-1  | 2022-11-28 13:02:35.227 UTC [28] ERROR:  update or delete on table "hfj_resource" violates foreign key constraint "fk_trmvalueset_res" on table "trm_valueset"
biobankhapi-fhir-jpaserver-db-1  | 2022-11-28 13:02:35.227 UTC [28] DETAIL:  Key (res_id)=(102) is still referenced from table "trm_valueset".
biobankhapi-fhir-jpaserver-db-1  | 2022-11-28 13:02:35.227 UTC [28] STATEMENT:  delete from hfj_resource where res_id=$1
hapi-fhir-jpaserver-start        | 2022-11-28 13:02:35.228 [http-nio-8080-exec-5] WARN  o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:137] SQL Error: 0, SQLState: 23503
hapi-fhir-jpaserver-start        | 2022-11-28 13:02:35.228 [http-nio-8080-exec-5] ERROR o.h.e.jdbc.spi.SqlExceptionHelper [SqlExceptionHelper.java:142] ERROR: update or delete on table "hfj_resource" violates foreign key constraint "fk_trmvalueset_res" on table "trm_valueset"
hapi-fhir-jpaserver-start        |   Detail: Key (res_id)=(102) is still referenced from table "trm_valueset".
hapi-fhir-jpaserver-start        | 2022-11-28 13:02:35.230 [http-nio-8080-exec-5] ERROR c.u.f.j.dao.expunge.PartitionRunner [PartitionRunner.java:73] Error while Expunging
hapi-fhir-jpaserver-start        | org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [fk_trmvalueset_res]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
hapi-fhir-jpaserver-start        |      at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:276)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.config.HapiFhirHibernateJpaDialect.convertHibernateAccessException(HapiFhirHibernateJpaDialect.java:121)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.config.HapiFhirHibernateJpaDialect.convertHibernateAccessException(HapiFhirHibernateJpaDialect.java:64)
hapi-fhir-jpaserver-start        |      at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233)
hapi-fhir-jpaserver-start        |      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:145)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
hapi-fhir-jpaserver-start        |      at jdk.proxy2/jdk.proxy2.$Proxy208.deleteByPid(Unknown Source)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ResourceExpungeService.expungeCurrentVersionOfResource(ResourceExpungeService.java:270)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ResourceExpungeService.expungeCurrentVersionOfResources(ResourceExpungeService.java:174)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ResourceExpungeService$$FastClassBySpringCGLIB$$193f4d58.invoke(<generated>)
hapi-fhir-jpaserver-start        |      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ResourceExpungeService$$EnhancerBySpringCGLIB$$d7b804d1.expungeCurrentVersionOfResources(<generated>)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.lambda$deleteCurrentVersionsOfDeletedResources$1(ExpungeOperation.java:123)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.PartitionRunner.lambda$buildCallableTasks$0(PartitionRunner.java:110)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.PartitionRunner.runInPartitionedThreads(PartitionRunner.java:70)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.deleteCurrentVersionsOfDeletedResources(ExpungeOperation.java:123)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.expungeDeletedResources(ExpungeOperation.java:91)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.call(ExpungeOperation.java:67)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeService.expunge(ExpungeService.java:65)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.forceExpungeInExistingTransaction(BaseHapiFhirResourceDao.java:910)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.expunge(BaseHapiFhirResourceDao.java:888)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao$$FastClassBySpringCGLIB$$5578fb67.invoke(<generated>)
hapi-fhir-jpaserver-start        |      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoValueSetR4$$EnhancerBySpringCGLIB$$3f33d596.expunge(<generated>)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider.doExpunge(BaseJpaResourceProvider.java:91)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider.expunge(BaseJpaResourceProvider.java:205)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
hapi-fhir-jpaserver-start        |      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseMethodBinding.invokeServerMethod(BaseMethodBinding.java:265)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:335)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.doInvokeServer(BaseResourceReturningMethodBinding.java:325)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.invokeServer(BaseResourceReturningMethodBinding.java:432)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:310)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.handleRequest(RestfulServer.java:1153)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.doPost(RestfulServer.java:424)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.service(RestfulServer.java:1862)
hapi-fhir-jpaserver-start        |      at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.starter.web.ExpiredTokenFilter.doFilterInternal(ExpiredTokenFilter.java:168)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilter(ResourceUrlEncodingFilter.java:67)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:122)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:116)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:109)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:223)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:217)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter.doFilterInternal(OAuth2AuthorizationRequestRedirectFilter.java:178)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:112)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
hapi-fhir-jpaserver-start        |      at java.base/java.lang.Thread.run(Thread.java:833)
hapi-fhir-jpaserver-start        | Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement
hapi-fhir-jpaserver-start        |      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:109)
hapi-fhir-jpaserver-start        |      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:37)
hapi-fhir-jpaserver-start        |      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
hapi-fhir-jpaserver-start        |      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
hapi-fhir-jpaserver-start        |      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:200)
hapi-fhir-jpaserver-start        |      at org.hibernate.hql.internal.ast.exec.BasicExecutor.doExecute(BasicExecutor.java:80)
hapi-fhir-jpaserver-start        |      at org.hibernate.hql.internal.ast.exec.BasicExecutor.execute(BasicExecutor.java:50)
hapi-fhir-jpaserver-start        |      at org.hibernate.hql.internal.ast.exec.DeleteExecutor.execute(DeleteExecutor.java:177)
hapi-fhir-jpaserver-start        |      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:458)
hapi-fhir-jpaserver-start        |      at org.hibernate.engine.query.spi.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:377)
hapi-fhir-jpaserver-start        |      at org.hibernate.internal.SessionImpl.executeUpdate(SessionImpl.java:1478)
hapi-fhir-jpaserver-start        |      at org.hibernate.query.internal.AbstractProducedQuery.doExecuteUpdate(AbstractProducedQuery.java:1714)
hapi-fhir-jpaserver-start        |      at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1696)
hapi-fhir-jpaserver-start        |      at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:241)
hapi-fhir-jpaserver-start        |      at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:90)
hapi-fhir-jpaserver-start        |      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:156)
hapi-fhir-jpaserver-start        |      at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:144)
hapi-fhir-jpaserver-start        |      at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:137)
hapi-fhir-jpaserver-start        |      at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:121)
hapi-fhir-jpaserver-start        |      at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:160)
hapi-fhir-jpaserver-start        |      at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:139)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:81)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
hapi-fhir-jpaserver-start        |      ... 143 common frames omitted
hapi-fhir-jpaserver-start        | Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "hfj_resource" violates foreign key constraint "fk_trmvalueset_res" on table "trm_valueset"   
hapi-fhir-jpaserver-start        |   Detail: Key (res_id)=(102) is still referenced from table "trm_valueset".
hapi-fhir-jpaserver-start        |      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2676)
hapi-fhir-jpaserver-start        |      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2366)
hapi-fhir-jpaserver-start        |      at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:356)
hapi-fhir-jpaserver-start        |      at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:490)
hapi-fhir-jpaserver-start        |      at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:408)
hapi-fhir-jpaserver-start        |      at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:181)
hapi-fhir-jpaserver-start        |      at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:149)
hapi-fhir-jpaserver-start        |      at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
hapi-fhir-jpaserver-start        |      at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
hapi-fhir-jpaserver-start        |      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
hapi-fhir-jpaserver-start        |      ... 167 common frames omitted
hapi-fhir-jpaserver-start        | 2022-11-28 13:02:35.231 [http-nio-8080-exec-5] ERROR c.u.f.r.s.i.ExceptionHandlingInterceptor [ExceptionHandlingInterceptor.java:174] Failure during REST processing
hapi-fhir-jpaserver-start        | ca.uhn.fhir.rest.server.exceptions.InternalErrorException: HAPI-1084: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [fk_trmvalueset_res]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.PartitionRunner.runInPartitionedThreads(PartitionRunner.java:74)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.deleteCurrentVersionsOfDeletedResources(ExpungeOperation.java:123)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.expungeDeletedResources(ExpungeOperation.java:91)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeOperation.call(ExpungeOperation.java:67)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.expunge.ExpungeService.expunge(ExpungeService.java:65)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.forceExpungeInExistingTransaction(BaseHapiFhirResourceDao.java:910)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.expunge(BaseHapiFhirResourceDao.java:888)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao$$FastClassBySpringCGLIB$$5578fb67.invoke(<generated>)
hapi-fhir-jpaserver-start        |      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
hapi-fhir-jpaserver-start        |      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
hapi-fhir-jpaserver-start        |      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoValueSetR4$$EnhancerBySpringCGLIB$$3f33d596.expunge(<generated>)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider.doExpunge(BaseJpaResourceProvider.java:91)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.provider.BaseJpaResourceProvider.expunge(BaseJpaResourceProvider.java:205)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
hapi-fhir-jpaserver-start        |      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
hapi-fhir-jpaserver-start        |      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseMethodBinding.invokeServerMethod(BaseMethodBinding.java:265)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:335)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.doInvokeServer(BaseResourceReturningMethodBinding.java:325)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.BaseResourceReturningMethodBinding.invokeServer(BaseResourceReturningMethodBinding.java:432)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.method.OperationMethodBinding.invokeServer(OperationMethodBinding.java:310)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.handleRequest(RestfulServer.java:1153)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.doPost(RestfulServer.java:424)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.rest.server.RestfulServer.service(RestfulServer.java:1862)
hapi-fhir-jpaserver-start        |      at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at ca.uhn.fhir.jpa.starter.web.ExpiredTokenFilter.doFilterInternal(ExpiredTokenFilter.java:168)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.web.servlet.resource.ResourceUrlEncodingFilter.doFilter(ResourceUrlEncodingFilter.java:67)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:327)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:115)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:81)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:122)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:116)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:126)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:81)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:109)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:149)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:223)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:217)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter.doFilterInternal(OAuth2AuthorizationRequestRedirectFilter.java:178)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:103)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:89)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:112)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:82)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:55)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:336)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:211)
hapi-fhir-jpaserver-start        |      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
hapi-fhir-jpaserver-start        |      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
hapi-fhir-jpaserver-start        |      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
hapi-fhir-jpaserver-start        |      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
hapi-fhir-jpaserver-start        |      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
hapi-fhir-jpaserver-start        |      at java.base/java.lang.Thread.run(Thread.java:833)

Environment (please complete the following information):

psavva commented 1 year ago

Dear @jamesagnew

Please let us know if you need any further details, we are happy to provide.

Best Regards Panayiotis Savva

jamesagnew commented 1 year ago

Two things that would be helpful:

  1. Confirm that this still happens on the current release of HAPI FHIR (6.2.1)
  2. Provide complete steps to reproduce against an otherwise empty database (looking at the above, probably only miossing the create step?)
PanayiotisCS commented 1 year ago

Hello @jamesagnew,

I followed the guide according to https://github.com/hapifhir/hapi-fhir-jpaserver-starter as I ran the server via Docker Hub.

After running the docker container with the new empty database I reproduced the following steps:

  1. Create a new value set
    curl --location --request POST 'http://localhost:8080/fhir/ValueSet' \
    --header 'Content-Type: application/json' \
  2. Delete the value set (id =1)
    curl --location --request DELETE 'http://localhost:8080/fhir/ValueSet/1' \
    --data-raw ''

    Response:

    {
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">INFORMATION</td><td>[]</td><td><pre>Successfully deleted 1 resource(s) in 7ms</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
    },
    "issue": [
        {
            "severity": "information",
            "code": "informational",
            "diagnostics": "Successfully deleted 1 resource(s) in 7ms"
        }
    ]
    }
  3. Expunge the deleted resource
    curl --location --request POST 'http://localhost:8080/fhir/ValueSet/1/$expunge' \
    --header 'Content-Type: application/json' \
    --data-raw '
    {
    "resourceType": "Parameters",
    "parameter": [
    {
      "name": "limit",
      "valueInteger": 1000
    },{
      "name": "expungeDeletedResources",
      "valueBoolean": true
    },{
      "name": "expungePreviousVersions",
      "valueBoolean": true
    }
    ]
    }'

    Response:

    {
    "resourceType": "OperationOutcome",
    "text": {
        "status": "generated",
        "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>HAPI-1084: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [&quot;FK_TRMVALUESET_RES: PUBLIC.TRM_VALUESET FOREIGN KEY(RES_ID) REFERENCES PUBLIC.HFJ_RESOURCE(RES_ID) (CAST(1 AS BIGINT))&quot;; SQL statement:\ndelete from hfj_resource where res_id=? [23503-214]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
    },
    "issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "HAPI-1084: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [\"FK_TRMVALUESET_RES: PUBLIC.TRM_VALUESET FOREIGN KEY(RES_ID) REFERENCES PUBLIC.HFJ_RESOURCE(RES_ID) (CAST(1 AS BIGINT))\"; SQL statement:\ndelete from hfj_resource where res_id=? [23503-214]]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"
        }
    ]
    }
hankwallace commented 1 year ago

I'm having the same issue using 6.2.2. While trying to diagnose an issue with $expand of ValueSet resources that we are creating, I following this thread: https://groups.google.com/g/hapi-fhir/c/Zl6C6SHYzlM

Steps to reproduce:

  1. GET the ValueSet from http://hapi.fhir.org/baseR4/ValueSet/address-use
  2. POST this ValueSet to my local server
  3. DELETE this ValueSet from my local server
  4. POST the $expunge operation for this resource from my local server
{
  "resourceType": "OperationOutcome",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>HAPI-1084: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [fk_trmvalueset_res]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
  },
  "issue": [
    {
      "severity": "error",
      "code": "processing",
      "diagnostics": "HAPI-1084: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [fk_trmvalueset_res]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement"
    }
  ]
}
jamesagnew commented 1 year ago

I've attempted to reproduce this but my test is passing - If anyone can see any difference between the test and your actual scenario (or if you can reproduce this on hapi.fhir.org) i'd love to see it.

Here's the test I added: https://github.com/hapifhir/hapi-fhir/pull/4509/files#diff-308f21ffaf90d666965a5134d1c0536987dbc890179f2e9a8c2e51e0cd1f4e08R263