mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-05-29 05:32:17 +00:00
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.i18n.HapiLocalizer;
|
||||||
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
|
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
||||||
|
import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.exception.ConstraintViolationException;
|
import org.hibernate.exception.ConstraintViolationException;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
@ -23,7 +24,7 @@ public class HapiFhirHibernateJpaDialect extends HibernateJpaDialect {
|
|||||||
protected DataAccessException convertHibernateAccessException(HibernateException theException) {
|
protected DataAccessException convertHibernateAccessException(HibernateException theException) {
|
||||||
if (theException instanceof ConstraintViolationException) {
|
if (theException instanceof ConstraintViolationException) {
|
||||||
if (ResourceHistoryTable.IDX_RESVER_ID_VER.equals(((ConstraintViolationException) theException).getConstraintName())) {
|
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 {
|
||||||
try {
|
try {
|
||||||
myPatientDao.update(updatePatient);
|
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());
|
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) {
|
} catch (Exception e) {
|
||||||
|
@ -147,8 +147,8 @@
|
|||||||
</action>
|
</action>
|
||||||
<action type="add">
|
<action type="add">
|
||||||
When two threads attempt to update the same resource at the same time, previously
|
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
|
an unspecified error was thrown by the JPA server. An HTTP 409
|
||||||
(Precondition Failed) with an informative error message is now thrown.
|
(Conflict) with an informative error message is now thrown.
|
||||||
</action>
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="3.3.0" date="2018-03-29">
|
<release version="3.3.0" date="2018-03-29">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user