Skip to Content

CAFLock Exception for Update method of CAF Entity Service

Hi All

I am using Adaptive web service model for my CAF Application Services , I have created Access methods (CRUD)for my Entity service in Application Service which is exposed as web service I am able to call n execute all the methods sucessfully except for update method for which I am gettimg CAFLockException

note that in create method I have following lines of code

( retvalue is of Entity Service type , systemCode is primary key on table others are non primary keys)

retValue = getSystemCodeService().create(systemCode);

retValue.setBusAct(busAct);

retValue.setCurrency(currency);

retValue.setDocType(docType);

retValue.setHeaderText(headerText);

retValue.setUserName(userName);

getSystemCodeService().update(retValue);

here record gets created sucessfully and update which is last line in above code also works fine

but when i seprately test update method in CAF Application Service exposed as web service I get CAFLockexception

here's what update method contains

getSystemCodeService().update(newobj);

while making call to this method I have ensured that I am supplying Key and SystemCode( which is custom primary key on table )

it seems when I used update in my create method at that time row got locked coz I tried to cross check with below code in my create method

retValue = getSystemCodeService().create(systemCode);

retValue.setBusAct(busAct);

retValue.setCurrency(currency);

retValue.setDocType(docType);

retValue.setHeaderText(headerText);

retValue.setUserName(userName);

getSystemCodeService().update(retValue);

getSystemCodeService().readSystemCodeRecord(new QueryFilter("dummy"));

retValue.setUserName("NEWUPDATED");

getSystemCodeService().update(retValue);

and it works only when I read some other record in table and again call update method i do not get Lock exception

if last four lines are changed to

getSystemCodeService().update(retValue);*

retValue.setUserName("NEWUPDATED");

getSystemCodeService().update(retValue);

I again get lock exception

looking at above pattern I tried adding this code in my CAF Application Service update method

getSystemCodeService().readSystemCodeRecord(new QueryFilter("dummy"));

getSystemCodeService().update(newobj);

ie do dummy read on some other record to remove lock on the record which i want to update , but did not suceed in that

please help me to update the record second time , can u tell me how to unlock this row or is there anything I am doing wrong

Thanks in Advance

Asif

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jan 18, 2008 at 06:49 AM

    problem got solved....

    CAF performs optimistic locking when updating. For this purpose it uses the lastChangedAt attribute of the business entity - if the value of the instance to be updated is different from the value in the database then the locking exception is thrown. solution is

    1. Call the read operation in order to obtain a business entity

    instances.

    2. Call the update operation using the attributes' values as received

    from the read operation + your changes. I.e. for the attributes which youdon't want to update, you must pass the same values as received from the read operation.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.