Entity locking question

When an entity has a @Version property, is it automatically version checked on flush/commit or lock() must be called in order for it to get this behaviour ?

Im talking in general, cos i am doing an API to be called from both standalone and server environment.
What should I do here ?
Please tell me the general rule..

Similar Messages

  • CAF Entity locking HELP

    hello
    I am doing some tests in WebDynpro and CAF Core services.
    I have a piece of code as below that retrieves an entity from CAF Core for update. I need this entity to be locked during the update but the two methods lock() and unlock() do nothing. I can still access for update the same entity instance from another user.
    This probably works if the transaction is happening within CAF service but I also need to lock entities from webdynpro when doing complex updates. In other words I am not willing to create a custom method in CAF service for each update I need to implement in webdynpro.
    Any advice ? How are we supposed to use the class com.sap.tc.col.client.generic.api.LockStrategy ? I did not find much about this api.
    Thanks in advance
    Vitaliano
      public void UpdateKAMInTransaction( )
        //@@begin UpdateKAMInTransaction()
         IServiceFacade serviceFacade = CAFServiceFactory.getServiceFacade(cplxmdlDefinition.class);
        String guid = wdContext.currentAKamElement().getGuid();
         AKam akam = MyAppProxy.readKam(guid);
         //locking is not working at all. concurrent changes are lost
         akam.lock(LockStrategy.EXCLUSIVE);
         //update a value here
         akam.setVersion(akam.getVersion() + 1);
         akam.getAspect().sendChanges();
         serviceFacade.save();
         //locking is not working at all. concurrent changes are lost
         akam.unlock();
         wdThis.wdGetAPI().getMessageManager().reportSuccess("done update AKAM=" + akam);
        //@@end

    Now I feel lost. Please keep helping a newby.
    I have implemented my custom method in CAF Services. Here I lock the entity, make all my chanegs, then update and return. I call this custom CAF Application Service method from WebDynpro.
    Nevertheless I noticed that concurrency can still happen. If more than one user updates the same entity at the same time, and exception is thrown in the log files but no exception is thrown. I.e. I cannot intercept the collision.
    in the log file a huge stacktrace is written, while the most interesting message is "javax.jdo.JDOUserException: optimistic transaction failed".
    So... what am I doing wrong here? Should'nt new locking just hold until the existing one is released?
    HELP!
    Vitaliano
         public java.lang.String myUpdateKam(java.lang.String guid, long newVersion) throws com.sap.caf.rt.exception.ServiceException
              // logging
              java.lang.String CAF_user = sessionContext.getCallerPrincipal().getName();
              java.lang.String CAF_methodHeader = MyAppBean.JARM_REQUEST + ":" + "myUpdateKam(java.lang.String, long)";
              Object[] CAF_parameters = new Object[] { guid, new java.lang.Long(newVersion)};
              com.sap.caf.rt.util.CAFPublicLogger.entering(CAF_user, MyAppBean.JARM_REQUEST, CAF_methodHeader, MyAppBean.location, CAF_parameters);
              java.lang.String retValue;
              try
                   //@@custom code start - myUpdateKam(java.lang.String, long)
                   //Read the BO and prepare for changes
                   retValue = "";
                   Kam kam = getKamService().read(guid);
                   char modeLock = IBusinessEntityService.MODE_WRITE;
                   try
                        //Lock BO before updating
                        try
                             getKamService().lock(kam.getKey(), modeLock, 3000);
                             retValue += "-lock-";
                        catch (CAFLockException e)
                             retValue += e.getMessage();
                        //Now do the update and commit
                        // =====> NOTE: regardelss if there is another update in progress,
                        // a concurrent update still gets down to here. WHY ?
                        long counter = kam.getVersion();
                        kam.setVersion(++counter);
                        getKamService().update(kam);
                        retValue += "-update-";
                   catch (CAFUpdateException e)
                        //This case is when concurrent update occurs
                        retValue += e.getMessage();
                   catch (Exception e)
                        //any other exception thrown?
                        retValue += e.getMessage();
                   finally
                        //Make sure we always leave our BO unlocked
                        try
                             getKamService().unlock(kam.getKey(), modeLock);
                             retValue += "-unlock-";
                        catch (CAFLockException e)
                             retValue += e.getMessage();
                   //@@custom code end - myUpdateKam(java.lang.String, long)
                   return retValue;
              finally
                   com.sap.caf.rt.util.CAFPublicLogger.exiting(CAF_user, MyAppBean.JARM_REQUEST, CAF_methodHeader, MyAppBean.location, CAF_parameters);
    This is the code in WebDynpro to invoke CAF custom method.
      public void UpdateKAMRemotely( )
        //@@begin UpdateKAMRemotely()
         IServiceFacade serviceFacade = CAFServiceFactory.getServiceFacade(cplxmdlDefinition.class);
         IAspect retValue = null;
         for (int i = 1; i < 101; i++)
              long newLong = wdContext.currentAKamElement().getVersion() +i;
              retValue = MyAppProxy.myUpdateKam(wdContext.currentAKamElement().getGuid(),newLong);
              IAspectRow row = retValue.getAspectRow(0);
              String retMsg = row.getAttributeAsString("value");
              wdThis.wdGetAPI().getMessageManager().reportSuccess("IAspectRow=" + row + "index="+i);
              serviceFacade.save();
        //@@end
    Message was edited by:
            Vitaliano Trecca

  • About session abnormal termination, table locked question.

    Hi all,
    i test some table lock,after i run this statement:
    select * from testt for update nowait;
    i abnormal terminate session, then the table testt will be locking until after 20 minutes,
    i checked some document, the parameter of SQLNET.EXPIRE_TIME = 5 in sqlnet.ora file can release that lock, i set with 5,and then test again, but still wait 20 minutes the lock can release, why?

    I've changed this now to use the URL variable. I am used to using that to go from a results page to a details page where the recordset on the details page is used. I hadn't realised that you could just set a link to:
    <a href="addNomination.php?LodgeID=<?php echo($_GET['LodgeID']); ?>">Add Nomination</a>
    where there is no recordset on a page, just for the purposes of passing the variable. (Yeah, I know - this is probably really basic!)
    I do have one last question on this though - my form action is:
    <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
    And then the link to a NominationAdded page is in the php code at the top of the AddNomination page:
    $ins_nominations->registerTrigger("END", "Trigger_Default_Redirect", 99, "NominationAdded.php");
    What would be useful would be to pass the URL variable through again, so that on the NominationAdded page I can have a link back to the same Lodge to add another Nomination without finding the Lodge again.
    But I'm not sure what the syntax would be, as it included some PHP within existing PHP, so not just:
    $ins_nominations->registerTrigger("END", "Trigger_Default_Redirect", 99, "nominationAdded.php?LodgeID=echo($_GET['LodgeID'])");
    I assume this must be possible, but not sure of the exact syntax?

  • File locking question

    Hello,
    We're considering using java to write in a new(to us) file system, OCFS2. However, this file system lacks certain features expected for file locking. Our app does not use java.nio.* that much, but it does use it. My question is what exact standards does the JVM require for file locking? Or is it ad hoc?
    If its ad hoc, what sys/func calls are required for locking?
    Thanks,

    The docs are rather specific that all of the functionality for FileLock is platform dependent.
    So you should test it.

  • Explicit Locking Question

    Dear all
    I have a question about <<Developer’s Guide>> Explicit Locking (27-3):
    "In a replicated cache, puts are blocked, but they are not blocked in a partitioned cache. "
    I want to know why "puts are not blocked in a partitioned cache."
    Thanks

    wangjw wrote:
    Dear all
    I have a question about <<Developer’s Guide>> Explicit Locking (27-3):
    "In a replicated cache, puts are blocked, but they are not blocked in a partitioned cache. "
    I want to know why "puts are not blocked in a partitioned cache."
    ThanksThe normal behaviour is that lock does not block anything other than another lock.
    The put-blocking behaviour at replicated caches is an anomaly which may be necessary due to backward compatibility reasons, or possibly a necessity due to the message flow for mutating operations in a replicated cache.
    So the question really would be why puts are blocked in a replicated cache, and I would also be interested in the answer, although I have my guesses.
    Best regards,
    Robert

  • Hashtable locking question

    I see that the put and get methods of Hashtable are synchronized, which is great for multi-thread execution, however, if outside the Hashtable class I use
    Hashtable t = new Hashtable();
    synchronized(t) {
       // loop over the hashtable in here and print out the values
    }is that synchronized block using the same lock as Hashtable's internal one? In other words, if I'm inside that synchronized block am I assured that no other thread can call get() or put()?
    I'm just looking for the proper way to iterate over the Hashtable while assuring myself it won't be modified.
    thanks!!!

    I looked up the SynchronizedMap source and don't see a big difference between it and Hashtable. SM uses synchronized blocks in every function and Hashtable uses synchronized methods. Is their a difference? If it's just a matter of one way being preferred over another let me know.
    Also, I'd still like an answer to my original question about the locks...is the object lock in a synchronized block the same as the class lock on that object's synchronized methods (see my example in post 1)?
    thanks!

  • Trivial Lock Question - nested synchronized instance method call

    Hi there. I have a question surrounding the following code block:
            public synchronized void bow(Friend bower)
                System.out.format("%s: %s has bowed to me!%n",
                        this.name, bower.getName());
                bower.bowBack(this);
            public synchronized void bowBack(Friend bower)
                System.out.format("%s: %s has bowed back to me!%n",
                        this.name, bower.getName());
            }If the bow method is invoked by the currently executing thread that has obtained the lock on the current instance and the
    call "bower.bowBack()" is invoked, what happens? Is the lock released then obtained again by the current thread? or does it hold onto it since the method
    "bowBack" is called within the method "bow"?
    Thank you!
    Regards

    thank you as always mr. verdagen!
    regards

  • Ipad mini auto lock question

    I put the auto lock to 10 mins but when my ipad mini is turned off and i turn it on with the little apple on the screen the screens seems to automatically turn off right after the lock screen appears. Is it normal?? I once had a samsung tab and it was doing that all the time and i realized it was messed up.
    Thank you. Have a nice day.

    My 32 GB iPad 2 has a capacity of 28.3 GB.
    It should be approximately the same for any 32 GB iPad.

  • Record Locking question

    Hi,
    I have the following situation:
    1) A batch process is running within a transaction with intension of commiting the changes at end if the process completes
    2) An online system (internet 3Tier app) issues an UPDATE statement on a record that is locked by the batch process. This UPDATE statement is not in a transaction.
    3) The problem is the UPDATE statement waits until the batch process either performs a COMMIT or ROLLBACK. I want it to return immediately so I can notify the online user.
    How can I have the UPDATE come back rather than wait. I do not really want to issue a SELECT statement with FOR UPDATE NOWAIT just before the UPDATE statement. Thanks in advance.

    Thanks for the reply.
    Normally I would use "select ... for update no wait" especially in desktop type applications. But in the internet world, when dealing with COM objects, ADO, and connection pooling, I cannot issue a start transaction, then issue select with for update nowait, and then show the html form to the user to make changes. The user may sit on the screen for a while. In the meantime, I have a database connection that is being tied up.
    So for record concurrency, we used a simple counter mechanism where any update (internet app, or desktop app) would update the counter. Any on update whe add this counter field to the where clause so if somone else has changed the data, the update would result in 0 rows affected. Normally this works well except in a situation where a desktop app is running a batch process and has not committed yet. In this case the update just waits.
    I know for if I juggle the data around a bit I can issue select for update no wait, then build the update recordset, and issue update, and them commit. I was looking for something that can return the update statement immediately with some sort of ORA error.
    Sorry for the long note.

  • Lifecycle designer 8 Field Locking question

    I have created a Remote access request form that is sent out to people when they need to connect to our network remotely. the form asks them to enter their contact details (Text field) and i have also created a table that asks what server they need access to (drop down list). However i also have text fields next to the drop down list. The user is only supposed to fill out their contact details and server name fields, then send it back to me and i will issue them an ip address, password etc. I will then save the form and send them a copy for reference. What i would like to do is lock down the form so they can only enter data in certain fields, but when it is sent back to me i can fill in the rest of the fields, ( ip address, password fields etc). Choosing to lock down a field after signing isn't any help to me because when they sign it and send back to me i want to be able to enter the rest of the information.
    Is there any possible work around to this.. how will the document know who has full access to it?
    Cheers,
    Dan
    IT Admin
    FEA LTD.

    A couple steps have to be made to have your form expand. Make sure when you save the form, it is saved as "Dynamic" and not "static".
    Also, make sure you click "Expand to fit" under "Height" in the Layout tab.
    If you want everything below your "expandable" section to move down, you will have to make sure all of those parts below are "wrapped" in a subform and the content is set to "flowed". You can wrap a "positioned" subform in a "flowed" subform.
    I hope this is some what helpful and understandable.

  • Database locking question

    Hi all,
    I have a small problem here that I've been trying to resolve for some time and couldn't come with a solution that "feels right".
    i'm working on a finance application where we have a table to
    keep a history of customer's transactions. The problem has to do with three fields:
    - customer's accountid
    - transaction amount
    - forward balance
    the first two are trivial, the last one is calculated on a row insertion: we get the last row for the account, and add the amount value from the new row(one being about to be inserted) the resulting amount becomes the new forward balance for the new row. This is like keeping the per-transaction account balance on a bank statement.
    Now, the problem is that we have several application servers inserting these rows into the same database in parallel. And now what happens is that if two servers are trying to insert rows (for different transactions but for the same acount) in the forward balance calculation logic both processes read the same last (old) row's forward balance and add that to their respective transactions' amounts and then record the new records. The forward balances in both new transactions are now screwed.
    I'm not sure how to fix this problem: I was reading about different database isolation levels and considered using pessimistic locks but all those mechanisms seem to solve problems with updating the same rows - not a combination of reading one row, and creating a new row with that row's result.
    Just to be complete: we are using MySQL (latest) with Hibernate 2.1.6 on Resin application server.
    Thank you in advance for any suggestions/recommendations/advice.
    -Oleg.

    You could move forward balance into its own table. That was, the SELECT will not lock on the original table. Most of the running balance schemes that I have seen take a snapshot as of a given date (say, statement printing date) and record both the timestamp and the amount. Next month, you simply get last month's vaule and timestamp and query on transactions after that timestamp.
    - Saish

  • Urgent: Entity Bean question

    Hi,
    I am using an entity beans to store and load records in a table. When I save records to the table I store them in an order of Primary key ID, but when loading the entity bean this order is not being preserved. Is there any way I can specify what the order (ascending or descending) the entiry bean needs to load records?
    Thanks.

    Dunno what exactly are you asking.
    I mean how are u making bulk entity bean save records?
    What exactly is the purpose ?
    Cheers,
    manjunath

  • Legal Consolidation: Entity structure question

    Hi Experts,
    Just want to ask if technical Entities are required in order for Legal Consolidation to work in SAP BPC 7.5 NW SP6? I'm using both R-Type (Currencies) and G-Type dimension (Conso Groups). In my first structure, I only have the following set up in my Entity and Groups dimension:
    Entity Dimension:
    ID          EVDESCRIPTION          PARENTH1     CURRENCY     INTCO     FX_TYPE     ELIM
    ALL_COMP     All Company                         
    COMPT1          Company Group 1          ALL_COMP                    
    COMP1          Company 1          COMPT1             USD          I_COMP1          Y
    COMP2          Company 2          COMPT1             USD          I_COMP2          Y
    COMPT2          Company Group 2          ALL_COMP                    
    COMP3          Company 3          COMPT2             USD          I_COMP3          Y
    COMP4          Company 4          COMPT2             USD          I_COMP4          Y
    Groups Dimension:
    ID          EVDESCRIPTION     CURRENCY_TYPE     ENTITY     GROUP_CURRENCY     PARENT_GROUP     STORE_ENTITY     STORE_GROUP_CURR     CONSO_TYPE     DATASRC_LEVEL     STAGE_ONLY     
    GCOMPT1     Company Group 1             G               USD                                   Y               A               
    GCOMPT2     Company Group 2             G               USD                                   Y               A               
    NON_GROUP     Non Group     
    In this set up, my Consolidation results in error "RUN_LOGIC:Accounts and entities do not match data in application OWNERSHIP". But if I change my set up to the following(with technical Entities), I don't get the error:
    Entity Dimension:
    ID          EVDESCRIPTION          PARENTH1     CURRENCY     INTCO     FX_TYPE          ELIM
    ALL_COMP     All Company                         
    COMPT1          Company Group 1          ALL_COMP                    
    COMP1          Company 1          COMPT1          USD               I_COMP1          
    COMP2          Company 2          COMPT1          USD               I_COMP2          
    COMPT2          Company Group 2          ALL_COMP                    
    COMP3          Company 3          COMPT2          USD               I_COMP3          
    COMP4          Company 4          COMPT2          USD               I_COMP4          
    ECOMPT1             Company Group 1                    USD                         Y
    ECOMPT2             Company Group 2                    USD                         Y
    Groups Dimension:
    ID          EVDESCRIPTION     CURRENCY_TYPE     ENTITY          GROUP_CURRENCY     PARENT_GROUP     STORE_ENTITY     STORE_GROUP_CURR     CONSO_TYPE     DATASRC_LEVEL     STAGE_ONLY     
    GCOMPT1     Company Group 1             G          ECOMPT1     USD                         Y          Y               A               
    GCOMPT2     Company Group 2             G          ECOMPT2     USD                         Y          Y               A               
    NON_GROUP     Non Group
    Am I just missing some properties or set up in my first that's why I'm getting the error or do I really need to create technical Entities for consolidation to work??
    Thanks,
    Marvin

    Hi nilanjan,
    I was pertaining to the Entities with ID that starts with "E". Anyway, I tried removing the values "Y" for property "ELIM" in the Entity dimension and removed the values for "ENTITY" and STORE_ENTITY in the Groups dimension and I don't encounter the error and consolidation calculates okay.
    Thanks,
    Marvin

  • Layer is Partially Locked question?

    I'm using Windows 7 64 bit but I use Photoshop CS5 32 bit.
    In my Layers Panel every file that I open up has that little icon (Indicates Layer is partially Locked).
      A lot of my functions are grayed out because of this condition. If I duplicate the Layer or put a selection around a layer or make a new layer (Layer 0) all previous grayed out functions now work.
    I uninstalled and reinstall PS CS 5 but still had the same problem. Is there something I can do about this condition?
                    Thank you

    I'm not sure if this is your problem, but every time an image is opened for the first time in Photoshop, there is one layer called Background.  This layer is automatically locked.  You can convert the Background layer into a normal (unlocked) layer by double-clicking on the word Background. You are prompted to give the layer another name (default is Layer 0).

  • Lock Question

    Hello,
    I have the following sentence on a procedure:
    LOCK TABLE ae_bc_trx IN ROW SHARE MODE;
    I need to know how to free the Lock in the same procedure or it liberates itself when I commit a transaction on the table?
    We are on DB 10g.
    Thanks

    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_9015.htm#SQLRF01605

Maybe you are looking for