Use HTTP 409 for conflict when two threds update the same resource
This commit is contained in:
parent
f1ba0016b2
commit
9d24e8b040
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.config;
|
|||
import ca.uhn.fhir.i18n.HapiLocalizer;
|
||||
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
|
||||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
@ -23,7 +24,7 @@ public class HapiFhirHibernateJpaDialect extends HibernateJpaDialect {
|
|||
protected DataAccessException convertHibernateAccessException(HibernateException theException) {
|
||||
if (theException instanceof ConstraintViolationException) {
|
||||
if (ResourceHistoryTable.IDX_RESVER_ID_VER.equals(((ConstraintViolationException) theException).getConstraintName())) {
|
||||
throw new PreconditionFailedException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceVersionConstraintFailure"));
|
||||
throw new ResourceVersionConflictException(myLocalizer.getMessage(HapiFhirHibernateJpaDialect.class, "resourceVersionConstraintFailure"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -444,7 +444,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test {
|
|||
try {
|
||||
try {
|
||||
myPatientDao.update(updatePatient);
|
||||
} catch (PreconditionFailedException e) {
|
||||
} catch (ResourceVersionConflictException e) {
|
||||
assertEquals("The operation has failed with a version constraint failure. This generally means that two clients/threads were trying to update the same resource at the same time, and this request was chosen as the failing request.", e.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -147,8 +147,8 @@
|
|||
</action>
|
||||
<action type="add">
|
||||
When two threads attempt to update the same resource at the same time, previously
|
||||
an unspecified error was thrown by the JPA server. An HTTP 412
|
||||
(Precondition Failed) with an informative error message is now thrown.
|
||||
an unspecified error was thrown by the JPA server. An HTTP 409
|
||||
(Conflict) with an informative error message is now thrown.
|
||||
</action>
|
||||
</release>
|
||||
<release version="3.3.0" date="2018-03-29">
|
||||
|
|
Loading…
Reference in New Issue