In ADF, often we see error saying ‘JBO-25014: Another user has changed the row with primary key oracle.jbo.Key’. The framework throws this error to make sure that none of the user changes are accidentally overwritten by another user and generally occurs when a user trying to modify record that has been just modified and committed by another user. In this post, we will see how to take care of this scenario using ADF BC REST services in context of HTTP PATCH.
ADF BC REST Services make use of attribute called changeIndicator which can be observed in response of GET.
Follow the steps mentioned below to enable this in a resource:
- EO should have an attribute marked as Change Indicator and set Track Change History as shown below.
- Add this attribute in VO i.e to be exposed as REST resource.
Deploy your changes and issue GET to observe changeIndicator as below.
for e.g. changeIndicator for department 10 (resource instance):
ACED0005737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D0300014900047
3697A65787000000001770400000001737200116A6176612E6C616E672E496E746567657212E2A0A4F7
81873802000149000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08
B02000078700000000178
Now update department 10 using following sql query to simulate the actual update.
update departments set department_name = ‘Administration-modified’, object_version_number = object_version_number+1
where department_id = 10
Issue GET again on same resource and observe the changeIndicator.
ACED0005737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D0300014900047
3697A65787000000001770400000001737200116A6176612E6C616E672E496E746567657212E2A0A4F7
81873802000149000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08
B02000078700000000378
As observed above, the value of changeIndicator changes with each update and is calculated by RESTServlet registered in web.xml of RESTWebService project.
Here is an interesting observation and do issue issuing GET for department 10.
http://localhost:7001/departmentApi/rest/r1/departments/10
If we observe HTTP response headers, the value of ETag is same as that of changeIndicator. Hence changeIndicator works in similar lines of ETag defined in HTTP specification.
Now let us observe the behavior of REST resource when ETag is used for If-Match/If-None-Match HTTP headers during GET and PATCH. Basically these HTTP headers tells server to do requested operation when sent Etag value matches or did not match respectively.
Make sure you enclose ETag value with “ (double quotes) as shown below.
If-None-Match:
Using GET:
- When resource is not modified, returns status code as 304.
- When resource is modified, returns response with new changeIndicator value.
Using PATCH:
- When resource is not modified, returns response status code as 412.
- When the resource is not modified, then returns response with new changeIndicator value after update.
If-None-Match |
Modified |
Not Modified |
GET |
Status:200 (Query Successful) |
Status: 304 |
PATCH |
Status: 200 (Update Successful) |
Status: 412 |
If-Match:
Using GET:
- When resource is not modified, resource is returned.
- When resource is modified, expected response status code is 304 but shows 200 with junk response.
Using PATCH:
- When resource is not modified, returns response with new change Indicator value after update.
- When resource is modified, expected response status code is 412 but shows 200 with junk response. However you will observe that the actual update is not happening though it returns 200.
If-Match |
Modified |
Not Modified |
GET |
Status:304 | Status:200 (Query Successful) |
PATCH |
Status:412 | Status: 200 (Update Successful) |
Note: As you observed above, ETag combination with If-Match header is not working as expected which is a bug in this release.
References:
1 Response to “ADF BC REST Services–II – Change Indicator”