Pessimistic locking Vs Optimitic locking  In ERP

Hi all
" Pessimistic locking Vs Optimistic locking To advice MY ERP "
Im SASI , Now I have a problem for using locking system in update problem
I am using Oracle 10g and Java 5.0(Netbeans)
My PL to advice for pessimistic locking system ,
Now I want to what is the difference between & How to help my ERP
I am reading lot of information they are all confuse to me.
1) Select .. for update nowait --> this statement will lock that record upto the user commit,
in my problem I am wait for the same record that fellow when will release I'm updated.
2) Do the modified (I have column upto 25 ) how to change to another transaction in some other table
ex orderdetails -order cancel
stock detail -stock maintain
orderdetails for update ........................... long time at the same time waiting for stock detail updatation .
ALL the guys How to handle the above top and I want solution above problem
very urgent .....
Thank
SASIKUMARA

Pessimistic Locking:
You lock any and all rows before you update them. In Oracle that is done with a SELECT FOR UPDATE.
Problem:
Stateless clients (like web clients/app tier connections) cannot use pessimistic locking as this locking is specific to a single Oracle session. These stateless clients can use/re-use/create any Oracle session. Thus should they attempt to lock rows in one session, that state information will be missing when they attempt to update the rows from another session.
Work-around - Optmistic Locking:
To work around this problem with stateless clients, optimistic locking is used. The client does not lock the rows it wants to update. It optimistically assume that the rows will be unchanged at the time it wants to update them.
When it does update the rows, it needs to check the existing copy of the row in the database, with the old copy of the row it retrieved from the database. If these two copies matches, then it can proceed to write the changed copy of the row.
This is usually done via an UPDATE SQL like this:
UPDATE emp
SET name = :newname, surname = :newsurname, ...
WHERE emp_id = :emp_id
AND name = :oldname
AND surname = :oldsurname
AND ... (for all other columns) As you can see, should any column in the row be changed from the last time that the client viewed the row, the UPDATE will fail to update the changed row.
Not implementing optimistic locking for stateless clients leads to issues like lost updates. Two clients update the same row - the 2nd client overwrites the changes of the 1st client and thus the 1st client's changes becomes lost.

Similar Messages

  • Pessimistic lock exception in a clustered environment

    Hello,
    i am using distributed Cache(DataCache) in a Cluster environment
    (Weblogic 7.0 cluster).
    I got one AdminServer and two ManagedServer running on the same machine.
    The problem occurs when i am using optimistic locking. It seems to be that
    the cache is not beeing synchronized, when i am successivly persisting
    objects and therfore get optimistic lock exceptions.
    When i am using pessimistic locking there is no problem.
    Waht could be the reason for this, maybe the case the all instances
    running on the same machine?
    My properties for the cache are the following:
    com.solarmetric.kodo.DataCacheClass=de.d2vodafone.webe.common.security.
    authorization.jdo.Cache (Cache is a subclass of UDPCache)
    com.solarmetric.kodo.DataCacheProperties=UseMulticast=true
    MulticastGroup=224.0.0.123 (is unique in my environment)
    In the log of my server i got the following messages:
    ignoring update from localhost
    ####<12.02.2003 13:25:11 CET> <Error> <EJB> <pc120514> <ManagedServer2>
    <ExecuteThread: '4' for queue: '__weblogic_admin_rmi_queue'> <kernel
    identity> <> <010026> <Exception during commit of transaction
    4:b57355e6636065c2: javax.jdo.JDOUserException: Errors were detected when
    flushing to the data store. If using optimistic transactions, this could
    indicate that lock violations were detected. The "getNestedExceptions"
    method of this Exception will return the specific errors.
    NestedThrowables:
    javax.jdo.JDOUserException:
    An instance was concurrently modified in another transaction (optimistic
    lock #: 3).
    FailedObject:de.webe.common.security.authorization.DomainImpl-5
         at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(PersistenceManagerImpl.java:551)
         at
    com.solarmetric.kodo.ee.EEPersistenceManager.beforeCompletion(EEPersistenceManager.java:192)
         at
    weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:540)
         at
    weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:92)
         at
    weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1044)
         at
    weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1581)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:237)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    NestedThrowablesStackTrace:
    javax.jdo.JDOUserException: An instance was concurrently modified in
    another transaction (optimistic lock #: 3).
    FailedObject:de.d2vodafone.webe.common.security.authorization.DomainImpl-5
         at
    com.solarmetric.kodo.impl.jdbc.ormapping.ClassMapping$1.afterUpdate(ClassMapping.java:611)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatementNonBatch(SQLExecutionManagerImpl.java:563)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatement(SQLExecutionManagerImpl.java:512)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executeInternal(SQLExecutionManagerImpl.java:406)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.flush(SQLExecutionManagerImpl.java:273)
         at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:421)
         at
    com.solarmetric.kodo.runtime.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:296)
         at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(PersistenceManagerImpl.java:549)
         at
    com.solarmetric.kodo.ee.EEPersistenceManager.beforeCompletion(EEPersistenceManager.java:192)
         at
    weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:540)
         at
    weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:92)
         at
    weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1044)
         at
    weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1581)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:237)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.d2vodafone.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.d2vodafone.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    --------------- nested within: ------------------
    weblogic.transaction.RollbackException: Unexpected exception in
    beforeCompletion: sync=com.solarmetric.kodo.ee.EEPersistenceManager@472ddf
    Errors were detected when flushing to the data store. If using optimistic
    transactions, this could indicate that lock violations were detected. The
    "getNestedExceptions" method of this Exception will return the specific
    errors. - with nested exception:
    [javax.jdo.JDOUserException: Errors were detected when flushing to the
    data store.  If using optimistic transactions, this could indicate that
    lock violations were detected.  The "getNestedExceptions" method of this
    Exception will return the specific errors.
    NestedThrowables:
    javax.jdo.JDOUserException: An instance was concurrently modified in
    another transaction (optimistic lock #: 3).
    FailedObject:de.d2vodafone.webe.common.security.authorization.DomainImpl-5]
         at
    weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1561)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:284)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    Thanks for your help
    Best Regards
    Orhan Keskin

    Orhan-
    Is this consistently reproducable, or a rare or one-time occurance? If
    the former, it may be a configuration issue, and we will investigatge
    along that path.
    If it is a rare or one-time occurance, keep in mind that data cache
    synchronization does not guarantee that you will be able to avoid
    optimistic locking exceptions. Whenever using optimistic locking, you
    always need to assume that someday, someone is going to violate that
    lock, unless you place some sort of synchronization atop all the
    database access (e.g., an EJB). It makes any application much more error
    prone (especially since an OL exception is a RuntimeException, and
    frequently people forget that it always needs to be checked for).
    Anyway, if you provide us with some more details, we will be able to
    investigate further.
    In article <[email protected]>, Orhan Keskin wrote:
    Hello,
    i am using distributed Cache(DataCache) in a Cluster environment
    (Weblogic 7.0 cluster).
    I got one AdminServer and two ManagedServer running on the same machine.
    The problem occurs when i am using optimistic locking. It seems to be that
    the cache is not beeing synchronized, when i am successivly persisting
    objects and therfore get optimistic lock exceptions.
    When i am using pessimistic locking there is no problem.
    Waht could be the reason for this, maybe the case the all instances
    running on the same machine?
    My properties for the cache are the following:
    com.solarmetric.kodo.DataCacheClass=de.d2vodafone.webe.common.security.
    authorization.jdo.Cache (Cache is a subclass of UDPCache)
    com.solarmetric.kodo.DataCacheProperties=UseMulticast=true
    MulticastGroup=224.0.0.123 (is unique in my environment)
    In the log of my server i got the following messages:
    ignoring update from localhost
    ####<12.02.2003 13:25:11 CET> <Error> <EJB> <pc120514> <ManagedServer2>
    <ExecuteThread: '4' for queue: '__weblogic_admin_rmi_queue'> <kernel
    identity> <> <010026> <Exception during commit of transaction
    4:b57355e6636065c2: javax.jdo.JDOUserException: Errors were detected when
    flushing to the data store. If using optimistic transactions, this could
    indicate that lock violations were detected. The "getNestedExceptions"
    method of this Exception will return the specific errors.
    NestedThrowables:
    javax.jdo.JDOUserException:
    An instance was concurrently modified in another transaction (optimistic
    lock #: 3).
    FailedObject:de.webe.common.security.authorization.DomainImpl-5
         at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(PersistenceManagerImpl.java:551)
         at
    com.solarmetric.kodo.ee.EEPersistenceManager.beforeCompletion(EEPersistenceManager.java:192)
         at
    weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:540)
         at
    weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:92)
         at
    weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1044)
         at
    weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1581)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:237)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    NestedThrowablesStackTrace:
    javax.jdo.JDOUserException: An instance was concurrently modified in
    another transaction (optimistic lock #: 3).
    FailedObject:de.d2vodafone.webe.common.security.authorization.DomainImpl-5
         at
    com.solarmetric.kodo.impl.jdbc.ormapping.ClassMapping$1.afterUpdate(ClassMapping.java:611)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatementNonBatch(SQLExecutionManagerImpl.java:563)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executePreparedStatement(SQLExecutionManagerImpl.java:512)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.executeInternal(SQLExecutionManagerImpl.java:406)
         at
    com.solarmetric.kodo.impl.jdbc.SQLExecutionManagerImpl.flush(SQLExecutionManagerImpl.java:273)
         at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.flush(JDBCStoreManager.java:421)
         at
    com.solarmetric.kodo.runtime.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:296)
         at
    com.solarmetric.kodo.runtime.PersistenceManagerImpl.flush(PersistenceManagerImpl.java:549)
         at
    com.solarmetric.kodo.ee.EEPersistenceManager.beforeCompletion(EEPersistenceManager.java:192)
         at
    weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:540)
         at
    weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:92)
         at
    weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1044)
         at
    weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1581)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:237)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.d2vodafone.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.d2vodafone.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    --------------- nested within: ------------------
    weblogic.transaction.RollbackException: Unexpected exception in
    beforeCompletion: sync=com.solarmetric.kodo.ee.EEPersistenceManager@472ddf
    Errors were detected when flushing to the data store. If using optimistic
    transactions, this could indicate that lock violations were detected. The
    "getNestedExceptions" method of this Exception will return the specific
    errors. - with nested exception:
    [javax.jdo.JDOUserException: Errors were detected when flushing to the
    data store.  If using optimistic transactions, this could indicate that
    lock violations were detected.  The "getNestedExceptions" method of this
    Exception will return the specific errors.
    NestedThrowables:
    javax.jdo.JDOUserException: An instance was concurrently modified in
    another transaction (optimistic lock #: 3).
    FailedObject:de.d2vodafone.webe.common.security.authorization.DomainImpl-5]
         at
    weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1561)
         at
    weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:284)
         at
    weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:208)
         at
    weblogic.ejb20.internal.BaseEJBObject.postInvoke(BaseEJBObject.java:278)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl.createUser(AuthorizationServiceBean_8zrrq4_EOImpl.java:170)
         at
    de.webe.common.security.authorization.jdo.AuthorizationServiceBean_8zrrq4_EOImpl_WLSkel.invoke(Unknown
    Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
         at
    weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
         at
    weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:785)
         at
    weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
         at
    weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
    Thanks for your help
    Best Regards
    Orhan Keskin
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • Pessimistic locking in a three-tier architecture

    Hello,
    we use a three-tier architecture to edit data in a database (Oracle 10g) with a rich-client application and we want to use pessimistic locking.
    The client is communicating with a stateless bean on the application server (Jboss 4.2.3).
    This bean-facade has methods for reading, writing and locking records that are transferred to the client encapsulated in entity beans.
    The client controls the transactions as JPA-User-Transactions.
    The methods in the container managed bean have the transaction attribute REQUIRED.
    Before doing any modification on the client a method setLock() is called in the bean to lock the records in the database.
    The lock is implemented with query hints:
    Query query = em.createQuery("select e from Person e WHERE e.id = 252");
    query.setHint(QueryHints.PESSIMISTIC_LOCK, PessimisticLock.LockNoWait);
    So much for this theroy...
    Practically we can set a lock on a record in the database.
    But removing the lock is working when changing and committing the record only.
    The record remains locked if performing a rollback or a commit without any changes.
    Any idea what's missing in our implementation?
    Our approach should work - theoretically...
    Thanks in advance for any hint
    Best regards,
    Martin Kubitza
    T&P, Bochum/Germany

    Thank you for the hint on JPA - we are analyzing this now.
    Meanwhile we tried something "easier": Optimistic locking
    Optimistic locking works well with a version-column and the @VERSION annotation. But we get a problem with the @OptimisticLocking(type = OptimisticLockingType.ALL_COLUMNS annotation (see Optimistic Locking with OptimisticLockingType.ALL_COLUMNS
    We are using Eclipselink V1.1 and (now) a bean managed transaction type)
    Martin Kubitza
    T&P, Bochum/Germany

  • Best way to handle pessimistic locking after dequeueing

    Dear all,
    we have a simple single-consumer scenario where multiple worker
    processes listen to one task queue. Every task is specific to exactly one business
    object that is pessimistically locked (SELECT FOR UPDATE) as soon as
    the AQ message has been fully parsed by a worker.
    Obviously, this may lead to unnecessary waiting. For example, when
    there are 5 successive messages belonging to the same business object,
    having them dequeued by 5 worker processes in parallel will result
    in 1 worker processing its task and 4 workers waiting.
    To me, this seems to be a common use case. How is it "usually"
    handled?
    Best regards,
    Michael

    Hi Paul!
    Thanks a lot for your answers that would completely solve
    my problem if I had another setting :-) . I try to clarify
    things by answering your questions (slightly reordered).
    I have to apologize in advance that I take my description to the
    next level of detail and hope not to deter you too much.
    3. Why is this a single consumer Q when you have multiple business
    areas hanging off it? It would seem an ideal candidate for having
    a subscriber per business area and then subsequently a worker per subscriber.Instead of a multi-subscriber setting, we employ multiple
    queues for different business areas and do some "queue routing"
    in our middle-ware. We wanted the different areas to become as
    detangled as possible (maybe that was unnecessary)
    2. Why lock the database object before processing the message?
    Cant you just rely on oracle's internal row locking mechanisms?
    Do you lock the whole table? If so why? First of all, we only lock one row that designates the "coarse-grained lock".
    I think you will understand this with the description below.
    We have one component that orchestrates our workflows and updates the
    states of our business objects. Let's assume, our basic "business object container"
    was called 'stream'. Different streams are guaranteed to be independent (and hence may be
    concurrently processed). So, a SELECT FOR UPDATE on a stream is enough
    to pessimistically lock the whole business object.
    Such a stream contains a complex graph of sub-objects. When the response
    of, e.g. a 'youtube syncer' component, comes in, the state of many
    objects in this graph may change (which we obviously want to do within a transaction).
    E.g. when all children of a node become READY,
    this node becomes READY which, in turn, may yield its
    parent READY.
    The problem with ordinary row-locking is now: responses for one stream tend to cluster,
    i.e. sometimes there are 100 responses in the queue for one stream, and as state
    updates often have large consequences for the whole state graph, blocking
    (or NOWAIT exceptions) are the rule not the exception, resulting in performance that
    is even worse than coarse-grained locking.
    1. Why have multiple processes DQ'ing from this Q?
    Is the message volume too great for one worker?Some tasks are long-running like transferring large files to remote hosts.
    With workers running on different hosts and networks we have nice
    load balancing.
    Even the short-running jobs take often >1s CPU time and batch
    jobs may generate several millions of AQ messages that we process
    in a cluster.
    Ok, if you reach this line, you certainly deserve my thankfulness :-)
    Best regards,
    Michael

  • Pessimistic Locking (relating to COBOL)

    Hi,
    Apologies for the SA I've written below - just wanted to explain the context around my problem.
    I'm working on an application which replaces the Micro Focus COBOL file handler & allows data in COBOL VSAM files to be migrated to Oracle in such a way that the COBOL source code doesn't have to change.
    The last problem we're having is in replicating COBOL's pessimistic locking paradigm in that a COBOL READ with LOCK statement will take a lock on the row that's read, and won't release the lock until an explicit UNLOCK statement is issued.
    Each IO command from COBOL ends up calling an Oracle procedure, so what I'm after is ideas on how to create a procedure which when called will select one record & create a row lock, and hold that lock until another stored procedure call (to the unlock) procedure is made.
    Using Select ... for update will work provided we're in a database transaction, however that causes other headaches because currently we're sharing one database connection across all files that are opened by a running COBOL program, & the files need to be locked & unlocked independently from each other.
    If that's the only way to achieve the lock I can work with that by changing our application to create a connection for a file when it needs to lock a record, but does anyone have any out of the box ideas?
    thanks, Darren.

    This is not an easy problem to solve due to a very big difference between file (ISAM) based locking and RDBMS transactions.
    A lock in a RBMS is not just a "mere row lock" - it is part of a transaction. And a lock cannot span a transaction. To emulate file-based locking in any RDBMS will be problematic as a result.
    It can be done in Oracle. Heck, there is little one cannot do in Oracle. However, some designs (like this file-based record locking) simply does not scale.
    And precisely for that reason, Oracle does not have a Lock Manager. There is no special monolithic structure (memory or table) that contains a list of locks. Any new lock, any release of an existing lock, will require access to that structure - and serialised access. This means it will become a huge bottleneck the more locks there are and the more processes wants locks. And this is the reason why there are lock escalation problems in SQL-Server, why locks are "expensive". Why the Ingres RDBMS manual goes into great lengths of how to "tune" the database for this, to the effect of having to decide whether to boost OLTP processing or read-only queries - as you cannot run both as effectively as you want.
    In order for you to emulate the file-lock approach, this is exactly what you will need to simulate in Oracle. A monolithic lock manager.
    Not that difficult to design and implement in Oracle. Pessimistic locking in Oracle is essentially "turned off" and you manage application row locking via your own PL/SQL lock manager in Oracle. Using autonomous transactions extensively.
    But this will not scale. Sure, it can handle maybe 200 users. Maybe more. But as the userbase increases, so the system will slow down - as you have no choice but to enforce serialisation in your PL/SQL lock manager to handling locking.
    There is a price to pay for not wanting to change the Cobol code to correctly use Oracle's concurrency model.
    Personally, I would argue long and very hard that this price is unacceptable and that none of the ROI in an "expensive" RDBMS is realised. Any RDBMS makes a very poor ISAM file system. So why bother?

  • Pessimistic lock problem with Sybase

    I am having a problem with performing pessimistic lock
    using Toplink and Sybase/HSQLDB.
    Code example:
    Object o = uow.readObject(...
    uow.refreshAndLock(o);
    //Change o
    uow.commitAndResume();
    ==========================
    I receive an Exception:
    Local Exception Stack:
    Exception [TOPLINK-4002] (OracleAS TopLink - 10g (9.0.4.2) (Build 040311)): oracle.toplink.exceptions.DatabaseException
    Exception Description: java.sql.SQLException: Unexpected token: FOR in statement [SELECT t0.CLASSIDENTIFIER, t0.DB_VERSION, t0.OBJECTID, t1.OBJECTID, t1.NAME, t1.DESCRIPTION, t1.TYPE, t2.OBJECTID, t2.MULTIPLE_SERVERS_POLICY, t2.OUTAGE_POLICY, t2.INCOMING_SCRIPT, t2.OUTGOING_SCRIPT, t2.OUTAGE_SCRIPT FROM ROOT t0, LDAPSERVICE t2, SERVICE t1 WHERE ((t0.OBJECTID = 252) AND (((t2.OBJECTID = t0.OBJECTID) AND (t1.OBJECTID = t0.OBJECTID)) AND (t0.CLASSIDENTIFIER = 'ORM.LdapService'))) [b]FOR UPDATE OF * NOWAIT]
    =================
    As you can see Toplink is trying to execute illegal statement : "....FOR UPDATE OF * NOWAIT"
    Do you have any idea what I'm doing wrong?

    Duplicate posting Pessimistic lock problem with Sybase

  • Pessimistic locking issues

    I don't understand how pessimistic locking works in Oracle ADF.
    I have created a page where I want to update the files of a table
    I use pessimistic locking (I know people recommend not to use it, but it's the only solution I can use)
    If I modify a row, when does the row lock start? I mean, when I start modifying nothing gets locked, but when I change the row (I go to the next row). The row modified gets locked. I want the row to be locked just after I have modified a field, not after I have gone to another record (just like Forms)
    Can somebody explain how to be able to lock a record once the user has started editing it?
    Thanks in advance

    Hi,
    ADF doesn't do any locking, its the business service doing this. So I assume you use ADF BC, though you don't mention it
    http://www.oracle.com/webapps/online-help/jdeveloper/10.1.2/state/content/navId.4/navSetId._/vtTopicFile.bc4j%7Ctransactions%7Cbc_alockingmodes~html/
    Frank

  • Pessimistic Locking

    In the Weblogic 5.1.0 documents it says that Weblogic employes pessimistic
              locking with Entity Beans. The implication being that there is one instance
              of the Entity Bean object for each row in the database.
              We have verified this to be the case when running a single instance of
              Weblogic. However when running a clustered instance we have seen an
              instance of a particular Entity Bean object show up on multiple instances on
              the cluster and it caused problems.
              Has anybody else experience this? I want to confirm that this is indeed the
              behavior to expect. This caveat is not talked about anywhere in the
              documentation. Basically pessimistic locking can be assumed for a single
              instance of weblogic however it doesnt really apply in a cluster because
              while there will be one instance of a particular primary key per instance
              that does not preclude multiple cluster instances from having the same
              primary key instance.
              If this is the case, what ways are there to maintain this behavior in a
              cluster?
              Thanks,
              Sergio
              

    This is the behaviour. There is a single instance of the bean per row only in
              one instance of WLS. You cannot avoid multiple instances of a database row in
              differenct servers in a cluster. In a clustered environment the one to write
              last is the winner in any case. If two or more instances try to write
              simultaneously then the database would still allow only one of them to write.
              Also try the following
              1. Set your transaction isolation level to serializable. This will have a total
              locking on the row and will lead to clients reading maybe stale data but not
              updating it simultaneously.
              2. Have a 'versioning' column. All the tables with the below problem will have a
              version column. Now, consider a row1 with the versionid as 1. Consider two
              instances A and B with beans a1 and b1 which have the versionid as 1. Now a1
              writes the data and updates versionid to 2. When b1 writes it has old versionid
              and so you could either allow it to write or not allow depending on your
              application.
              Shiva.
              Sergio Mendez wrote:
              > In the Weblogic 5.1.0 documents it says that Weblogic employes pessimistic
              > locking with Entity Beans. The implication being that there is one instance
              > of the Entity Bean object for each row in the database.
              >
              > We have verified this to be the case when running a single instance of
              > Weblogic. However when running a clustered instance we have seen an
              > instance of a particular Entity Bean object show up on multiple instances on
              > the cluster and it caused problems.
              >
              > Has anybody else experience this? I want to confirm that this is indeed the
              > behavior to expect. This caveat is not talked about anywhere in the
              > documentation. Basically pessimistic locking can be assumed for a single
              > instance of weblogic however it doesnt really apply in a cluster because
              > while there will be one instance of a particular primary key per instance
              > that does not preclude multiple cluster instances from having the same
              > primary key instance.
              >
              > If this is the case, what ways are there to maintain this behavior in a
              > cluster?
              >
              > Thanks,
              >
              > Sergio
              

  • Pessimistic Locking mechanism in SAP Gateway.

    Hi All,
               I am new to SAP Gateway. I know there are two types of locking mechanism ( optimistic and pessimistic) . Optimistic we do by etag and if-match.
    Is there any idea of how to do by pessimistic approach.
    For example we are reading a contract and then updating it. So, in get_entity we have to put the lock while reading and we have to unlock while updating. But how does it works. Whether the lock automatically get released after the get_entity method.
    Kindly guide me in proceeding further.

    Hi Sundar,
    Here is my opinion :
              Gateway is Completely Stateless till the current version which is SP8. So Pessimistic Locking would not be available out of the box by Gateway. You need to implement your custom logic to achieve this behaviour. However simulating a Pessimistic Lock in a complete stateless architecture will lead to many complexities which often might lead to inconsistency in the Application.  As mentioned by Krishna, you can store lock information in some table in backend , but it might get messy very easily. I would not recommend to do so. However if you are really keen to do Pessimistic Locking kind of mechanism, what about the following approach -----
    1. In the OData service, let us have an extra Entity  called LOCK which has properties such as USER, RESOURCE_ID(such as contract ID),DATE,TIME. USER and RESOURCE_ID is the key in this entity. This data is stored in a table in database.
    2. When a particular USER  opens the CONTRACT screen in EDIT mode, the UI fires a POST(Create) call for Entity LOCK with the USER and RESOURCE_ID(contract ID in this case). In the backend database table if no entry exists with that USER ID and RESOURCE_ID, then a new entry is created and the USER is allowed to EDIT the contract. If an entry already exist in table then it means some other user is already in Edit mode , and the current user is refused to access the resource in edit mode.
    3. When the USER saves the CONTRACT you need to fire a DELETE request for that Particular LOCK entity. Thus is resource is dequeued.
    However this is like a vanilla flow. Handling can be complicated if user closes the browser, disconnects the network connection, opens parallel session etc etc.
              Rather a clean approach would be an Optimistic lock. Fiori Applications are using this mechanism to handle concurrency control. You may refer to my reply on Locking mechanism in SAP Gateway. for a little more information on Optimistic Locking.
    I agree that even though Optimistic locking works pretty well in REST based applications as it allows operations to be free from overhead of long transaction , there can be situations as mentioned below, where an Optimistic lock might not be preferred -
    1. Where the chances of concurrency collision is very high (Example: Online Reservation of Tickets)
    2. If modifying the resource by the user requires a lot of typing (However JS libraries such as Garlic.js, sisyphus.js or HTML5 Local storage can help us here )
    Now it is upto you to decide upon the approach ..

  • Isolation level and optimist/pessimist locking

    I am using baen managed transaction in which i have set the isolstion level according to my use...
    Now whrer does the concept of Optimist/pessimist locking comes if i have set the isolation level(it should be always pessimist locking in this case??) ???

    I am using baen managed transaction in which i have set the isolstion level according to my use...
    Now whrer does the concept of Optimist/pessimist locking comes if i have set the isolation level(it should be always pessimist locking in this case??) ???

  • How to implement Pessimistic Locking?

    Hello,
    I am using JDev 10g with integrated mapping workbench. There are option to set up optimistic locking, but I would like to implement pessimistic locking. How do I approach this?
    Thanks,
    Dmitry.

    Dmitry,
    Pessimistic locking is not configured on the descriptor it is executed at the API level on either a session or query. If you are using the UnitOfWork directly then I would recommend looking in the docs at
    UnitOfWork.refreshAndLockObject(Object)
    UnitOfWork.refreshAndLockObject(Object, short lockMode)
    If you wish to configure it on a query you can look at:
    ObjectLevelReadQuery.setLockMode(short lockMode)
    ObjectLevelReadQuery.acquireLocks()
    ObjectLevelReadQuery.acquireLocksWithoutWaiting()
    In the case of a query it should only be executed against a UnitOfWork where the database TX can be started to maintain the database locks.
    Doug

  • Need help in Pessimistic locking

    I am getting the Maiximum of primaryKey field using reportquery ..now i want to lock the object of the report query. i am doing as following
    ExpressionBuilder exp=new ExpressionBuilder();
    ReportQuery query=new ReportQuery();               
    query.setReferenceClass(Abc.class);               
    query.addAttribute("memberId",exp.get("memberId").maximum());
    query.acquireLocksWithoutWaiting();          
    Vector results = (Vector)uow.executeQuery(query);
    System.out.println("results---->"+results);
    now i increment the value of primary key as follows
    ReportQueryResult result1=(ReportQueryResult)results.get(0);          
    System.out.println("hello"+result1.getByIndex(0));
    Integer ctr=(Integer)result1.getByIndex(0);
    System.out.println("ctr:-"+ctr);
    int count=ctr.intValue();
    count=count+1;
    System.out.println("incrementedValue:-"+count)
    here i insert the new record to the database ;;
    the whole code work fine but when i trying to implement the pessimistic locking by
         query.acquireLocksWithoutWaiting();     
    it will gives the following error..Please help me ..thanks in Advance     
    ServerSession(28523022)--Connection(27817788)--SELECT MAX(MemberId) FROM Abc FOR UPDATE OF * NOWAIT
    Local Exception Stack:
    Exception [TOPLINK-4002] (OracleAS TopLink - 10g (9.0.4.5) (Build 040930)): oracle.toplink.exceptions.DatabaseException
    Exception Description: com.sybase.jdbc3.jdbc.SybSQLException: Incorrect syntax near '*'.
    Internal Exception: com.sybase.jdbc3.jdbc.SybSQLException: Incorrect syntax near '*'.
    Error Code: 102
         at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:227)
         at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:698)
         at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:506)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:131)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:115)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelectCall(CallQueryMechanism.java:194)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.selectAllRows(CallQueryMechanism.java:565)
         at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:733)
         at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:694)
         at oracle.toplink.queryframework.ReportQuery.execute(ReportQuery.java:442)
         at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:493)
         at oracle.toplink.queryframework.ReadQuery.execute(ReadQuery.java:125)
         at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:1958)
         at oracle.toplink.threetier.ServerSession.internalExecuteQuery(ServerSession.java:629)
         at oracle.toplink.threetier.ClientSession.internalExecuteQuery(ClientSession.java:392)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1086)
         at oracle.toplink.publicinterface.UnitOfWork.internalExecuteQuery(UnitOfWork.java:2189)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1086)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1038)
         at com.pearson.Test.Test.insert(Test.java:664)
         at com.pearson.Test.Test.main(Test.java:78)
    Caused by: com.sybase.jdbc3.jdbc.SybSQLException: Incorrect syntax near '*'.
         at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
         at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
         at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown Source)
         at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
         at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown Source)
         at com.sybase.jdbc3.jdbc.SybStatement.queryLoop(Unknown Source)
         at com.sybase.jdbc3.jdbc.SybStatement.executeQuery(Unknown Source)
         at com.sybase.jdbc3.jdbc.SybPreparedStatement.executeQuery(Unknown Source)
         at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:802)
         at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:651)
         ... 19 more

    I will explain you what I am trying to do:- we want to allocate the primary key to each new inserted row. suppose there are more than one user who are trying to insert the record in the database on the click of save button..how we can handle this situation by allocating them unique Id to each row..how we can genrate unique primary key to all the users who are inserting the new rows.
    Please help me how can i genrate unique primary key if more than one user inserting the data in the database. As you said use sequencing in toplink how can i use this?our database is sybase is it support Pessimistic locking or optimistic locking. need urgent help
    thanks in advance

  • Pessimistic locking with Oracle10gAS (10.0.3) Toplink CMP

    Hi,
    I try to work with Toplink CMP on the preview of the Oracle Application Server 10g (10.0.3). I use the workbench to create the toplink-ejb-jar.xml file.
    I have some problems to use the pessimistic locking. I enabled locks for a method with the name findAndLockByPrimaryKey. The SELECT * FROM XXX FOR UPDATE statement is created correctly, however an other 'data base connection' is used for the update statement. Is it possible
    to activate a data base transaction with toplink CMP which starts with a find method and ends when the Session Bean is removed.
    Thanks for help.

    I found the following entry in the Developer Preview Release Notes:
    <opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
    <toplink:cmp-descriptor xsi:type="toplink:cmp-descriptor">
    <toplink:pessimistic-locking xsi:type="toplink:pessimistic-locking-policy">
    <toplink:locking-mode>no-wait</toplink:locking-mode>
    </toplink:pessimistic-locking>
    </toplink:cmp-descriptor>
    </opm:class-mapping-descriptor>
    But I didn't find an option in the workbench to generate
    this entry and I'm not able to put this entry into my toplink-ejb-jar.xml file.
    Can anybody help me?

  • JPA Pessimistic Locking

    Hi,
    Can anybody tell me why the following ain't working?
    I'm trying to implement a J2SE client that will update objects using pessimistic locking. I've created the simplest testcase for some testing, but I can't seem to get it right, I must be overlooking something I guess...
    TestCase:
    //...imports and package declaration
    public class ToplinkLockingTestCase extends TestCase {
    private EntityManager entityManager;
         @Override
         protected void setUp() throws Exception {
    entityManager = Persistence.createEntityManagerFactory("default").createEntityManager();
         public void testUpdateWithPessimisticLock() throws Exception {
              final long sendingId = 991L;
              entityManager.getTransaction().begin();
              Query query = entityManager.createQuery("SELECT sending FROM ProductiveSending sending WHERE sending.id = :id");
              query.setParameter("id", sendingId);
              query.setHint(TopLinkQueryHints.PESSIMISTIC_LOCK, PessimisticLock.Lock);
              Sending sending = (Sending) query.getSingleResult();
              sending.setAcceptedAmount(sending.getAcceptedAmount() + 10);
              LOGGER.info("Sending --> " + sending);
              entityManager.getTransaction().commit();
    The problem with the example above, is that the invocation of the setter, setAcceptedAmount() deadlocks. The process just stops, I guess it's waiting upon release of a lock. However, since I'm on the same client, I would expect that the lock has been taken by the same client that is trying to invoke the update, is it not?
    What I can see from the output logging is that the SELECT ... FOR UPDATE is using another Connection(ID) than the UPDATE statement. How is that possible?
    [TopLink Finer]: 2007.11.19 02:10:35.146--ServerSession(25877218)--Thread(Thread[main,5,main])--client acquired
    [TopLink Finest]: 2007.11.19 02:10:46.422--UnitOfWork(18686163)--Thread(Thread[main,5,main])--Execute query ReportQuery(be.cm.apps.tpb.business.domain.sending.ProductiveSending)
    [TopLink Fine]: 2007.11.19 02:10:46.452--ServerSession(25877218)--Connection(20536747)--Thread(Thread[main,5,main])--SELECT Zending_Id, Facturatie_Mode_Cd, Aanvaard_Bdr, Verworpen_Bdr, File_Naam, Ontvangst_Dt, Geannuleerd_Ind, Facturatie_Type_Cd, Verworpen_Blokk_Error_Ind, Totaal_Lijnen, Verworpen_Drempel_Ind, Medium_Ontbreekt_Ind, last_positie, Totaal_Bdr, Laatste_Wijz_Id, Verwerking_Tijd, RowVersion, Verwerking_Dt, Ucp_Ziekenfonds_Nr, Process_Instance_Id, Antw_Verstuurd_Dt, Verworpen_Lijnen, Derde_Instelling_Ref , Facturatie_Jaar, Zending_Nr, Facturatie_Maand, Versie_Nr, Derde_Nummer, Verworpen_Uniciteit_Ind FROM SREFTPB_ZENDING WHERE ((Zending_Id = ?) AND (Facturatie_Mode_Cd = ?)) FOR UPDATE
         bind => [991, P]
    [TopLink Finest]: 2007.11.19 02:10:46.762--UnitOfWork(18686163)--Thread(Thread[main,5,main])--Register the existing object Sending[id=991, sendingNumber=492, thirdNumber=71014688, invoicingMonth=8, invoicingYear=2007, fileName=10061122.000, versionNumber=1]
    [TopLink Finest]: 2007.11.19 02:10:46.772--UnitOfWork(18686163)--Thread(Thread[main,5,main])--Revert the object's attributes Sending[id=991, sendingNumber=492, thirdNumber=71014688, invoicingMonth=8, invoicingYear=2007, fileName=10061122.000, versionNumber=1]
    [TopLink Finest]: 2007.11.19 02:10:46.772--UnitOfWork(18686163)--Thread(Thread[main,5,main])--track pessimistic locked object Sending[id=991, sendingNumber=492, thirdNumber=71014688, invoicingMonth=8, invoicingYear=2007, fileName=10061122.000, versionNumber=1] with UnitOfWork 18.686.163
    JUnitConfigurationHelper - The LogManager 4.3.1 is properly initialized and logs to the junit console
    20071119:14:11:03:336|DEBUG|be.cm.apps.tpb.business.domain.ToplinkLockingTestCase|INFO|Sending --> Sending[id=991, sendingNumber=492, thirdNumber=71014688, invoicingMonth=8, invoicingYear=2007, fileName=10061122.000, versionNumber=1]
    [TopLink Finer]: 2007.11.19 02:11:11.238--UnitOfWork(18686163)--Thread(Thread[main,5,main])--begin unit of work commit
    [TopLink Finer]: 2007.11.19 02:11:11.248--ClientSession(17385679)--Connection(5501096)--Thread(Thread[main,5,main])--begin transaction
    [TopLink Finest]: 2007.11.19 02:11:11.248--UnitOfWork(18686163)--Thread(Thread[main,5,main])--Execute query UpdateObjectQuery(Sending[id=991, sendingNumber=492, thirdNumber=71014688, invoicingMonth=8, invoicingYear=2007, fileName=10061122.000, versionNumber=1])
    [TopLink Finest]: 2007.11.19 02:11:11.248--UnitOfWork(18686163)--Thread(Thread[main,5,main])--Assign return row DatabaseRecord(
         SREFTPB_ZENDING.RowVersion => 12)
    [TopLink Fine]: 2007.11.19 02:11:11.258--ClientSession(17385679)--Connection(5501096)--Thread(Thread[main,5,main])--UPDATE SREFTPB_ZENDING SET Aanvaard_Bdr = ?, RowVersion = ? WHERE ((Zending_Id = ?) AND (RowVersion = ?))
         bind => [40.0, 12, 991, 11]

    OK so in the end I decided to switch to Eclipse Link and used the query hints feature to add exclusive locks to my objects (rows), if another client tries for the same lock then an exception is thrown after a timeout occurs. If the default timeout is lowered in MySQL then only a short delay is incurred by doing this.
    In summary something like:
    try {
                    Query q = em.createNamedQuery("Object.ObjectById");
                    q.setHint(QueryHints.PESSIMISTIC_LOCK, PessimisticLock.Lock);
                    q.setParameter("ObjectId", id);
                    Ob = q.getSingleResult();
                } catch (DatabaseException ex) {
                    System.out.println("DB Exception " + ex.getDatabaseErrorCode());
                    if (ex.getDatabaseErrorCode() == 1205) {
                        System.out.println("Lock wait timeout");
                }additionally in your MySQL my.cnf file or as a start up option set
    innodb_lock_wait_timeout=0
    it should be noted that on MySQL will only work with InnoDB tables.

  • How to implement the pessimistic locking using toplink with sybase

    we want to allocate the unique primary key to each row when many user try to insert the records concurrently..So what we are trying to do is we calculate the maximum of Primary Key and incremented it by 1. Now we want to Apply the locking concept on the so that unique key will be allocated to each newly inserted row
    Can you please tell me
    1. how we can genrate unique primary key in toplink using sybase?
    2.how to implement the pessimistic or optimistic locking ?which one will be preferable?

    Hi brother
    I think that this link can help you
    http://download-east.oracle.com/docs/cd/A97688_16/toplink.903/b10064/database.htm#1007986
    Good luck

Maybe you are looking for

  • How SAP standard run the interest calculation in AR module

    Dear expert, would like to seek for your advise, how SAP standard run the interest calculation in AR module ? Also advise,does the interest calculation generate the interest base on the dunning run?What are relationship between interest calculation g

  • Fill-in PDF forms and save with no error messages. How?

    I've saved a Reader Extended PDF enabling form fill-in and save, but users report error saying, "WITHOUT THE OWNER PASSWORD YOU DO NOT HAVE PERMISSION TO SAVE THIS DOCUMENT." What do I need to do enable them to fill-in and save with no errors?

  • HELP: iMac won't boot up.

    Old iMac, due for replacement.  Working as expected until other day.  Now won't boot past initial apple splash screen, then dies after 10 seconds.

  • Subcontracting with chargeable components Node missing

    Dear Experts, Our system is ERP EHP5 SPS05. In SPRO under MM - Inventory Management and Physical Inventory - the node Subcontracting with chargeable components is missing Please help. Thanks.

  • Workflow: moving images on disk

    I just cant seem to bend lightroom to my prefferred workflow Whenever I import a whole bunch of images into one location, i find it such a faff to move these within lightroom to where I want them to finally reside.  lets say I import them to  D:/hold