Optimistic locking and HTML DB checksum calculation

I create a form for fetching and updating row from a database table. I use Automated Row Fetch for fetching row. But for updating row I must use a procedure from a package, not Automatic Row Processing (DML).
And my question is: how I can implement optimistic locking in this way?
Automated Row Fetch already calculated checksum and stored it in p_md5_checksum hidden field, can I get calculated value of checksum from p_md5_checksum?
How I can calculate checksum by myself for compare with value from p_md5_checksum?
What algorithm uses HTML DB for calculate checksum in Automated Row Fetch and Automatic Row Processing (DML) components?

I have read this topic already. It's recommended to build own functionality for calculate checksum, but Automated Row Fetch already calculated checksum and stored it in p_md5_checksum hidden field.
I also created my own function, for example for table dept:
create or replace function BUILD_DEPT_MD5 (
P_DEPTNO in number,
P_DNAME in varchar2 default null,
P_LOC in varchar2 default null,
P_COL_SEP in varchar2 default '|') return varchar2 is
begin
return utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string => P_DEPTNO || P_COL_SEP || P_DNAME || P_COL_SEP || P_LOC));
end BUILD_DEPT_MD5;
but checksum values what calculated with this function is not equal with checksum value calculated by Automated Row Fetch.
I shall specify:
I need to use Automated Row Fetch for get row from table.
I can not use Automatic Row Processing (DML) for update row, I need use PL/SQL procedure for this.
I want implement optimistic locking and I want use for this a checksum value, what already calculated by Automated Row Fetch. I need to know how I can get this checksum value and I need to know algorithm, which Automated Row Fetch uses for checksum calculation.

Similar Messages

  • Toplink Optimistic Locking not working with Session Bean facade.

    I am working on Oracle JDeveloper v 10.1.2 and connecting to an Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit
    The application is based on J2EE architecture and the technology stack uses Struts for presentation/controller framework, Stateless Session EJBs as session facade for custom business services, Simple java classes for the business services, Toplink implementation of DAO layer, Domain objects are mapped to database tables using Toplink Workbench that ships with JDeveloper. The transaction is managed by the session bean and hence the toplink session is configured to use external transaction controller and a named datasource as follows.
    <session xsi:type="server-session">
    <name>DBSession</name>
    <server-platform xsi:type="oc4j-1012-platform"/>
    <event-listener-classes/>
    <logging xsi:type="toplink-log">
    <log-level>fine</log-level>
    <file-name>D:/ToplinkLog.log</file-name>
    </logging>
    <primary-project xsi:type="xml">META-INF/toplink-descriptor.xml</primary-project>
    <login xsi:type="database-login">
    <platform-class>oracle.toplink.platform.database.oracle.Oracle10Platform</platform-class>
    <external-connection-pooling>true</external-connection-pooling>
    <external-transaction-controller>true</external-transaction-controller>
    <sequencing>
    <default-sequence xsi:type="native-sequence">
    <name>Native</name>
    <preallocation-size>1</preallocation-size>
    </default-sequence>
    </sequencing>
    <datasource>jdbc/ORADS</datasource>
    </login>
    </session>
    We intend to use Optimistic Locking based on Timestamp-version locking through an audit field "last_modification_date" of type java.sql.Timestamp. The corresponding database field is also of type Timestamp(6). We are not storing the version in cache.
    The problem we are facing is as follows.. we have an edit screen from where user can edit values for a domain object which are then persisted using Toplink...we expect Toplink to check the database record version (modification_date timestamp) before it applies the update. In DAO implementation, we register the object in a unitOfWork, then set the modified values, however we leave the modification_date (version field) unedited. Now when the application is running, on edit, an exception is thrown by the Session bean before ending the transaction.
    com.evermind.server.rmi.OrionRemoteException: Transaction was rolled back: Error in transaction: java.lang.NullPointerException
         at TrackingMediator_StatelessSessionBeanWrapper2.editOverheadExpenditure(TrackingMediator_StatelessSessionBeanWrapper2.java:1597)
         at com.enbridge.dsm.web.action.TrackingPortfolioAction.editOverheadExpenditure(TrackingPortfolioAction.java:264)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java)
         at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:278)
         at com.enbridge.dsm.web.shared.BaseAction.execute(BaseAction.java:90)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:465)
         at com.enbridge.dsm.web.shared.DSMPojoRequestProcessor.process(DSMPojoRequestProcessor.java:182)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1425)
         at com.sourcebeat.strutslive.common.SLActionServlet.process(SLActionServlet.java:44)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
         at com.enbridge.dsm.web.shared.security.SecurityFilter.doFilter(SecurityFilter.java:142)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:645)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
         Nested exception is:
    java.lang.NullPointerException
         at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:1190)
         at com.evermind.sql.FilterConnection.commit(FilterConnection.java:209)
         at com.evermind.sql.DriverManagerXAConnection.commit(DriverManagerXAConnection.java:203)
         at com.evermind.server.TransactionEnlistment.commit(TransactionEnlistment.java:251)
         at com.evermind.server.ApplicationServerTransaction.singlePhaseCommit(ApplicationServerTransaction.java:745)
         at com.evermind.server.ApplicationServerTransaction.commit(ApplicationServerTransaction.java:690)
         at com.evermind.server.ApplicationServerTransaction.end(ApplicationServerTransaction.java:1035)
         at TrackingMediator_StatelessSessionBeanWrapper2.editOverheadExpenditure(TrackingMediator_StatelessSessionBeanWrapper2.java:1593)
         at com.enbridge.dsm.web.action.TrackingPortfolioAction.editOverheadExpenditure(TrackingPortfolioAction.java:264)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java)
         at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:278)
         at com.enbridge.dsm.web.shared.BaseAction.execute(BaseAction.java:90)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:465)
         at com.enbridge.dsm.web.shared.DSMPojoRequestProcessor.process(DSMPojoRequestProcessor.java:182)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1425)
         at com.sourcebeat.strutslive.common.SLActionServlet.process(SLActionServlet.java:44)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
         at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
         at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
         at com.enbridge.dsm.web.shared.security.SecurityFilter.doFilter(SecurityFilter.java:142)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:645)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
         at java.lang.Thread.run(Thread.java:534)
    Note that the exception is thrown at the time when the session bean is about to commit the transaction. i.e. the DAO code did not throw any exception and was able to check the optimistic locking and submit the update transaction.
    I am not able to understand why is the the EJB throwing this weird error with Optimistic locking implementation. The application is working fine when the optimistic locking is disabled.
    I am facing another problem due to this problem... since the session bean throws this exception after exiting the bean implemented method, when trying to commit the transaction, I am not able to mark the session context to setRollbackOnly. Hence if I continue on to another transaction by navigating to another screen in the application, mysteriously the previous transaction gets committed!!... again... weird...

    I am using JDBC driver version 10.1.2.
    I saw this additional error message in JDeveloper console, which for some reason was not logged to my log4j log file... if it helps...
    06/09/22 18:32:10 Thr[thread 6]-TransactionEnlistment.TransactionEnlistment.Caught forgetandRollback XAException e null
    Here are the logs from my Toplink log file....
    [TopLink Info]: 2006.09.22 06:31:46.546--ServerSession(989)--Thread(Thread[HttpRequestHandler-86,5,main])--TopLink, version: Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)
    [TopLink Info]: 2006.09.22 06:31:46.578--ServerSession(989)--Thread(Thread[HttpRequestHandler-86,5,main])--Server: Oracle Application Server Containers for J2EE 10g (10.1.2.0.0)
    [TopLink Config]: 2006.09.22 06:31:46.593--ServerSession(989)--Connection(991)--Thread(Thread[HttpRequestHandler-86,5,main])--connecting(DatabaseLogin(
         platform=>Oracle10Platform
         user name=> ""
         connector=>JNDIConnector datasource name=>jdbc/ORADS
    [TopLink Config]: 2006.09.22 06:31:47.484--ServerSession(989)--Connection(1432)--Thread(Thread[HttpRequestHandler-86,5,main])--Connected: jdbc:oracle:thin:@10.210.16.37:1521:orabld
         User: APP_USR
         Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver Version: 10.1.0.3.0
    [TopLink Config]: 2006.09.22 06:31:47.500--ServerSession(989)--Connection(1433)--Thread(Thread[HttpRequestHandler-86,5,main])--connecting(DatabaseLogin(
         platform=>Oracle10Platform
         user name=> ""
         connector=>JNDIConnector datasource name=>jdbc/ORADS
    [TopLink Config]: 2006.09.22 06:31:47.500--ServerSession(989)--Connection(1434)--Thread(Thread[HttpRequestHandler-86,5,main])--Connected: jdbc:oracle:thin:@10.210.16.37:1521:orabld
         User: APP_USR
         Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
         Driver: Oracle JDBC driver Version: 10.1.0.3.0
    [TopLink Info]: 2006.09.22 06:31:47.671--ServerSession(989)--Thread(Thread[HttpRequestHandler-86,5,main])--DBSession login successful
    [TopLink Fine]: 2006.09.22 06:31:47.703--ServerSession(989)--Connection(1554)--Thread(Thread[HttpRequestHandler-86,5,main])--select * from user_role ur, app_resource ar, role_resource rr where rr.APP_RESOURCE_ID = ar.APP_RESOURCE_ID and rr.USER_ROLE_ID = ur.USER_ROLE_ID
    [TopLink Fine]: 2006.09.22 06:31:49.937--ServerSession(989)--Connection(10245)--Thread(Thread[HttpRequestHandler-86,5,main])--SELECT * FROM PROGRAM_SUB_CAT
    [TopLink Fine]: 2006.09.22 06:31:50.015--ServerSession(989)--Connection(10332)--Thread(Thread[HttpRequestHandler-86,5,main])--SELECT PROGRAM_ID, CREATED_BY_USERID FROM (SELECT CREATED_BY_USERID, ROWNUM PROGRAM_ID FROM (SELECT DISTINCT(CREATED_BY_USERID) CREATED_BY_USERID, 1 AS PROGRAM_ID FROM PROGRAM))
    (I only see my application specific queries after this... no exceptions or debug logs)... as I said before.. the application gives exception in the session bean at the time of commit, and there's no exception raised from Toplink code in DAO...

  • Locking and non-persistent changes in cache

    I have a question regarding Optimistic locking and modifying objects in the cache.
    I have a case where one client modifies a (persistent) object, but since it is a temporary change, which should not be persisted, it is not within a UOW. However, when the next client reads the same object, it gets the modified value and not the original value, which is not correct.
    For the moment, there are no locking defined for the descriptors, but would Optimistic locking help in this case? Does this not only protect when you try to write a change on a stale object to the database?
    If you run the risk that someone might change an object, and consequently change the cache and how the object is seen by others, should the reads be performed in a UOW?
    Regards,
    Katarina

    Yes, if you may make changes to the object you must make the changes in the unit of work, even if you do not intend to commit the changes. Reads from the session are strictly read-only.

  • Query using Optimistic Locking

    Hello all ,
    "With optimistic locking, a resource is not actually locked when it is first is accessed by a transaction."
    Is optimistic locking used for banking applications ??
    Please share your ideas , share your ideas.Thanks in advance.

    Can optimistic locking be used for banking applications? Sure. Is it always appropriate for every possible banking related application? No.
    You'll need to be a lot more specific about your application's requirements before we can say anything with much specificity. In general, banking or non-banking, OLTP applications ought to be using optimistic locking and any application that uses pessimistic locking needs to be careful not to hold locks across user interaction events (i.e. don't allow a user to lock a row and then head out to lunch without releasing the lock).
    Justin

  • Optimistic locking/ data concurrency and consistency

    Hi,
    When creating a tabular form using wizard, apex creates its own processes for optimistic locking. But when creating a form on a table, it doesn't create the processes. I suppose I need to create them manually.
    Can anybody show me the steps?
    Thanks!

    Scott,
    Thanks once again.
    2 things:
    My understanding is that I can't change the error message, and that if I want to customize the error message, I need to create my own process for checksum. Is this true? If so, what is the easiest way of doing this?
    I realized it returns an error message and the changes the user made gets lost if he went out for lunch and somebody else made an update on that record. What can I do so the user doesn't lose the data?
    Thanks,

  • Optimistic Lock with Parent and Child relationships

    Hi,
    I just have a question regarding optimistic locking. We have a scenario
    where a parent object has many child objects. Both the parent and the
    child objects have a jdolockx column in the database/jdo file.
    It appears that whenever you add a new child to the parent the parent's
    optimistic lock counter is also updated.
    eg
    parent.getChildren().add(child);
    child.setParent(parent);
    Why does this occur? There is no change made to the database table for
    the parent, except for the jdolockx column. Is there something that I can
    do to stop the lock count from incrementing when I child is added?
    We have a scenario where we have many threads of execution wishing to add
    children to a single parent. The parent itself isnt modified but this
    operation fails due to the parent lock counter being incremented.
    Any help would be appreciated
    Thanks
    Luke

    There is state image indicator in Kodo 3 which has more locking options
    beyond a simple number:
    http://solarmetric.com/Software/Documentation/3.0.1/docs/ref_guide_mapping_versionind.html#state-image
    In addition, you can plug your own version indicator.
    Our default optimistic locking avoids the problem of users having no
    idea what is -actually- in the collection/set at any given time.
    Inconsistencies can occur at the datastore level (user 1 adds
    object a to collection, user 2 removes a, user 1 adds object b... which
    should actually be in the DB? {a,b} or or {a}? This is one of the
    many ways in which not tracking changes to a collection/set can be
    hazardous).
    On locking exceptions, errors could be handled in some appropriate
    function (i.e. refresh, re-apply changes if applicable/safe,
    and commit).
    Luke wrote:
    Hi,
    I just have a question regarding optimistic locking. We have a scenario
    where a parent object has many child objects. Both the parent and the
    child objects have a jdolockx column in the database/jdo file.
    It appears that whenever you add a new child to the parent the parent's
    optimistic lock counter is also updated.
    eg
    parent.getChildren().add(child);
    child.setParent(parent);
    Why does this occur? There is no change made to the database table for
    the parent, except for the jdolockx column. Is there something that I can
    do to stop the lock count from incrementing when I child is added?
    We have a scenario where we have many threads of execution wishing to add
    children to a single parent. The parent itself isnt modified but this
    operation fails due to the parent lock counter being incremented.
    Any help would be appreciated
    Thanks
    Luke
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • Shuttle item and optimistic lock

    Hi everyone,
    I need to use a shuttle item to insert/update some data in a table. Because of that, I need to have a pl/sql process that will have the insert or update commands, so no DML allowed in my app page. By doing this, I lose the optimistic lock implemented within the DML process, so I've been searching and reading on how to accomplish this manually.
    I followed this post (Re: Optimistic locking on manual non-tabular form among others but it doesn't work properly.
    Is there another way to get the optimistic lock manually?
    Or better yet, is there a way to update a table from a shuttle item with DML?
    btw, i'm using apex 4.1.
    Thanks!
    Elena.

    Hello Elena,
    >> tab := apex_util.string_to_table (:p1_multiple_item);
    Yes. This is what I meant in parsing the shuttle value.
    >> Maybe I'm wrong, but this implies no use of DML, doesn't it?
    You are not wrong, although the correct term would be Automatic DML, which is a built-in APEX process (The term DML refers to any insert/update/delete database operation, regardless of APEX).
    You didn’t specify if you are familiar with the Optimistic Locking algorithm (which, BTW, pertains only to update data). In any case, my suggestion to you is to use the SQL Workshop to generate a package on your relevant table, and examine the update procedure that was generated. This procedure implements the Optimistic Locking algorithm and can be a great starting point for you to adapt it to your specific needs.
    You can generate the package using SQL Workshop ==> Object Browser ==> Create ==> Package ==> Package with methods on database table(s) .
    Hope it helps,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • Turn off optimistic locking to prevent ORA-20001

    Hi there,
    Is it possible to turn-off optimistic locking for tabular forms generated by wizard?
    I am using APEX 2.2.0.
    I am having ORA-20001 update errors, the only person who is using the form is me. I have read in this forum the solutions some of you have posted to resolve ora-20001 update or delete failures but they all do not work.
    I have also read that a turn on and off future will be available in APEX 3.0
    Do maybe know how I can turn-off the optimistic locking for my table.
    Regards
    RobH

    I think that the checksum is calculated from the values in the editable fields (hidden or otherwise) when the query is done. If you disable a field later on then it is not included in the checksum for the multi-record update, so you'll get an error when you submit changes.
    This isn't anything to do with whether fields are shown or not, but I've just encountered this problem and found there's nothing about it on the forums. Since your problem is also not on the forums I thought it might be the same thing.

  • Error in Update Process for optimistic locking

    Hello,
    I tried to create a tabular form according to this How-To:
    http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html
    which worked fine until I tried to implement the optimistic locking.
    I use the same update process:
    declare
    l_cks wwv_flow_global.vc_arr2;
    j pls_integer := 1;
    begin
    -- Get original MD5 checksum
    select wwv_flow_item.md5(job,mgr,hiredate,sal,comm,deptno) cks
    BULK COLLECT INTO
    l_cks
    from emp;
    -- Compare the original checksum, l_cks,
    -- with submitted checksum, htmldb_application.g_fcs.
    -- If they are different, raise an error.
    for i in 1..l_cks.count
    loop
    if htmldb_application.g_fcs(i) != l_cks(i) then
    rollback;
    raise_application_error(
              -20001,
         'Current version of data in database has changed '||
              'since user initiated update process.');
    return;
    end if;
    end loop;
    but as soon as I try to apply the changes in the update process I get an error message saying: PLS-00503: RETURN statement required for this return from function
    So, if i delete the row with the "return;" statement, I get no error anymore, but when I test the optimistic locking I get an error as soon as I try to update a row in the first place.
    What am I doing wrong?
    Johnny
    P.S. : I am using Apex 1.6

    Hi Ant, of course......here is the customized pl/sql block I use:
    declare
    l_cks wwv_flow_global.vc_arr2;
    j pls_integer := 1;
    begin
    -- Get original MD5 checksum
    select wwv_flow_item.md5(partition,desig) cks
    BULK COLLECT INTO
    l_cks
    from UNITS;
    -- Compare the original checksum, l_cks,
    -- with submitted checksum, htmldb_application.g_fcs.
    -- If they are different, raise an error.
    for i in 1..l_cks.count
    loop
    if htmldb_application.g_fcs(i) != l_cks(i) then
    rollback;
    raise_application_error(-20001,'Current version of data in database has changed ' || 'since user initiated update process.');
    -- return;
    end if;
    end loop;
    -- update UNITS
    for i in 1..htmldb_application.g_f08.count
    loop
    if htmldb_application.g_f08(i) is not null then
    update UNITS
    set report_id = :P2_REPORT_ID,
    partition = htmldb_application.g_f10(i),
    desig = htmldb_application.g_f11(i)
    where unit_id = htmldb_application.g_f08(i);
    else
    if htmldb_application.g_f10(i) is not null then
    insert into UNITS
    (report_id,
    partition,
    desig)
    values
    (:P2_REPORT_ID,
    htmldb_application.g_f10(i),
    htmldb_application.g_f11(i));
    end if;
    end if;
    end loop;
    end;
    Thanks
    Johnny

  • Em.merge does not throw Optimistic Lock Exception

    Hello,
    we are using Optimistic Lock Exception in a stateful bean managed transaction.
    I am wondering that there is no Optimistic Lock Exception is thrown after em.merge
    The Optimistic Lock Exception is primary thrown on em.flush - is this right?
    A similar problem is described on
    http://www.nabble.com/Optimistic-Lock-Exception-expected-td22742662.html#a22742662
    See serveroutput: The EclipseLink-5006-Exception is thrown after an em.flush
    14:03:11,657 INFO [STDOUT] updateItem
    14:03:11,657 INFO [STDOUT] [EL Finest]: 2009-04-09 14:03:11.657--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--Merge clone with references com.tup.model.Person@131a24c
    14:03:11,657 INFO [STDOUT] merged
    14:03:11,657 INFO [STDOUT] [EL Finest]: 2009-04-09 14:03:11.657--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--Execute query UpdateObjectQuery(com.tup.model.Person@196649c)
    14:03:11,657 INFO [STDOUT] [EL Fine]: 2009-04-09 14:03:11.657--ClientSession(21268424)--Connection(25845065)--Thread(WorkerThread#0[192.168.1.217:4518])--UPDATE mku_person_ver SET first_name = ? WHERE ((ID = ?) AND (((last_name = ?) AND (first_name = ?)) AND (version = ?)))
    bind => [Bernd 982, 5, Kuls, Bernd 98, 2009-04-09 13:12:15.0]
    14:03:11,672 INFO [STDOUT] [EL Warning]: 2009-04-09 14:03:11.672--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--Exception [EclipseLink-5006] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.OptimisticLockException
    Exception Description: The object [com.tup.model.Person@196649c] cannot be updated because it has changed or been deleted since it was last read.
    Class> com.tup.model.Person Primary Key> [5]
    14:03:11,688 INFO [STDOUT] [EL Warning]: 2009-04-09 14:03:11.688--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--javax.persistence.OptimisticLockException: Exception [EclipseLink-5006] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.OptimisticLockException
    Exception Description: The object [com.tup.model.Person@196649c] cannot be updated because it has changed or been deleted since it was last read.
    Class> com.tup.model.Person Primary Key> [5]
    14:03:11,688 INFO [STDOUT] OptimisticLockException throws MyApplicationException
    14:03:11,688 INFO [STDOUT] MyApplicationException
    14:03:11,735 INFO [STDOUT] [EL Finer]: 2009-04-09 14:03:11.735--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--TX afterCompletion callback, status=ROLLEDBACK
    14:03:11,750 INFO [STDOUT] [EL Finer]: 2009-04-09 14:03:11.75--UnitOfWork(14218007)--Thread(WorkerThread#0[192.168.1.217:4518])--release unit of work
    14:03:11,750 INFO [STDOUT] [EL Finer]: 2009-04-09 14:03:11.75--ClientSession(21268424)--Thread(WorkerThread#0[192.168.1.217:4518])--client released
    14:03:11,750 ERROR [BMTInterceptor] BMT stateful bean 'ModelFacade' did not complete user transaction properly status=STATUS_MARKED_ROLLBACK
    And by this Exception the transaction's status is set to status=STATUS_MARKED_ROLLBACK.
    The transaction can no longer be used.
    I want to use this transaction further and wrap the OptimisticLockException into an MyApplicationException
    (see serveroutput).
    But no change!
    Any Ideas ?
    Regards,
    Martin Kubitza
    T&P Bochum/Germany

    Hi,
    are you using JPA or TopLink ? Check if there is another exception thrown that produces the error. You can try and catch (Exception ex), which will catch them all. if this works the obviously you don't catch the right exception
    I found a post saying that: "If you trying commit directly after persist w/o doing an explicit
    flush then OptimisticLocking Exception maybe nested inside
    RollBackException. What is the top most error on stack? You can catch
    javax.persistence.PersistenceException and try to do this kind of
    error translation
    public static void getThrowable(javax.persistence.PersistenceException
    perex, int code) {
    boolean updateError = false ;
    boolean deleteError = false ;
    KentException kentex = null ;
    Throwable th = null ;
    if( perex instanceof org.apache.openjpa.persistence.RollbackException) {
    th = perex.getCause();
    if(th instanceof OptimisticLockException) {
    updateError = true ;
    if(perex instanceof OptimisticLockException ){
    updateError = true ;
    th = perex ;
    if(perex instanceof org.apache.openjpa.persistence.EntityNotFoundException) {
    deleteError = true ;
    th = perex ;
    http://n2.nabble.com/OptimisticLockException-confusion.-td210621.html
    Frank

  • Optimistic Locking - Specifying an alternative User message

    Scenario...
    User A selects a record
    User B selects the same record
    User A makes a change and commits/applies it
    User B makes a change to the same record and ties to commit
    Result...User B gets the following message...
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1, ORA-20001: ORA-20001: Current version of data in database has changed since user initiated update process. current checksum = "56693D48DF0C4F9D2A06AE5976FA6E8F", item checksum = "FC863259F75396F19D003B6B5E687758"., update "MAPOWN"."MAP_ALERT_LEVELS" set "MEASURE_ID" = :b1, "MEASURE_DESC" = :b2, "WARN_DFT" = :b3, "DANGER_DFT" = :b4, "WARN_TMP" = :b5, "DANGER_TMP" = :b6, "RECOMMENDATION" = :b7
    PROBLEM
    How do I capture this message and present a more user-friendly one??
    regards
    Paul P

    Paul - I don't know of a way around this other than to code your own optimistic locking logic and raise/handle an exception before the automatic row processing process catches it.
    Scott

  • Reading lock and pk column values

    Hi!
    I was wondering whether it is possible to somehow read the value a
    persistent object has for its lock column (JDOLOCKX by default) and pk
    column (with datastore identity, JDOIDX by default).
    Especially reading the lock would be useful. My specific problem is this:
    in J2EE environment when a persistent object is serialized and given to the
    web (or any other ui-) layer to display, its identity is lost. There are
    nice examples for solving this problem in the documentation so this is not
    an issue. However, there is no easy way to determine whether someone else
    changed the same data while it was being watched (and modified) on the web
    page. So, in essence, this is an optimistic transaction. However, to use
    optimistic transactions one would have to use stateful session beans. And
    if I am correct, an optimistic transaction has to have a live persistence
    manager all the time, so this is not acceptable unless the
    persistencemanager releses its sql connection in between calls. I don't
    think it does, or does it? And anyhow, I'd prefer using stateless session
    beans.
    It would be quite easy to implement some sort of timestamp mechanism by
    inserting a persistent field for it and updating its value by using
    InstanceCallback interface. However, as the JDOLOCKX column already exists
    it would be nice not to reinvent the wheel.
    The pk value I would need in case the same db is used by many apps (not
    all in Java) and they need to communicate some information about a specific
    object stored in the db (in which case it would be easiest to give the pk
    value to identify an object). Again, I could use ApplicationIdentity or
    make some field where to store some unique value, but I'd prefer using the
    pk value since it is already there (and would not like to use Application
    Identity just because of this).
    Any other solutions to the above problems besides being able to read the
    JDOIDX and JDOLOCKX values are welcome, too.
    -Antti

    You can either parse the toString () generated from
    JDOHelper.getObjectId () or cast it to ObjectIds.Id (in 2.5.x) or Id (in
    3.0) to get the pk value.
    You can also retrieve the lock version in the same fashion.
    In Kodo 3:
    KodoHelper.getVersion (yourPC).
    In Kodo 2.5.x:
    ((PersistenceManagerImpl) pm).getState (JDOHelper.getObjectId
    (yourPC)).getVersion ();
    Antti Karanta wrote:
    On Tue, 14 Oct 2003 10:46:56 -0400, Patrick Linskey
    <[email protected]> wrote:
    Based on your description of your problem, you might want to look at the
    new attach/detach functionality in Kodo 3.0:
    http://solarmetric.com/Software/Documentation/3.0.0RC2/docs/ref_guide_detach.html
    This functionality is a preview of a proposed JDO 2.0 feature, and is
    targeted at exactly the use case that you've described.Yes, it definitely looks nice. One thing it does not mention, though:
    is the String stored in the detached-objectid-field just the (string
    version of the) primary key or is there something else there?
    And what about a case where I do not want a detachable instance, just
    want to be able to have the primary key value?
    And I take it there is no way to read these values (lock and pk) in the
    present version of Kodo?
    On Tue, 14 Oct 2003 18:38:21 +0300, Antti Karanta wrote:
    Hi!
    I was wondering whether it is possible to somehow read the value a
    persistent object has for its lock column (JDOLOCKX by default) and
    pk column (with datastore identity, JDOIDX by default).
    Especially reading the lock would be useful. My specific problem is
    this: in J2EE environment when a persistent object is serialized and
    given to the web (or any other ui-) layer to display, its identity is
    lost. There are nice examples for solving this problem in the
    documentation so this is not an issue. However, there is no easy way
    to determine whether someone else changed the same data while it was
    being watched (and modified) on the web page. So, in essence, this is
    an optimistic transaction. However, to use optimistic transactions
    one would have to use stateful session beans. And if I am correct, an
    optimistic transaction has to have a live persistence manager all the
    time, so this is not acceptable unless the persistencemanager releses
    its sql connection in between calls. I don't think it does, or does
    it? And anyhow, I'd prefer using stateless session beans.
    It would be quite easy to implement some sort of timestamp mechanism
    by inserting a persistent field for it and updating its value by
    using InstanceCallback interface. However, as the JDOLOCKX column
    already exists it would be nice not to reinvent the wheel.
    The pk value I would need in case the same db is used by many apps
    (not all in Java) and they need to communicate some information about
    a specific object stored in the db (in which case it would be easiest
    to give the pk value to identify an object). Again, I could use
    ApplicationIdentity or make some field where to store some unique
    value, but I'd prefer using the pk value since it is already there
    (and would not like to use Application Identity just because of this).
    Any other solutions to the above problems besides being able to read
    the JDOIDX and JDOLOCKX values are welcome, too.
    -Antti
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • Ipod write protection error - disk is locked and cannot be written to

    Has anyone experienced this 'disk is locked and cannot be written to' when trying to update their ipod mini? I've tried everything, including all 4 R's, but still get the same message. And now that i've restored my ipod to its factory settings, I can no longer see my ipod in iTunes 7. So frustrating! Any thoughts are appreciated...i've just about given up. thanks.
    iPod Mini   Windows XP Pro  

    Welcome to Apple Discussions!
    First off, make sure everything is updated...
    http://www.apple.com/ipod/download
    http://www.apple.com/itunes/download
    Now see if restoring your iPod helps...
    http://docs.info.apple.com/article.html?artnum=60983
    btabz

  • 'This disk is locked and cannot be written to'

    After transferring music to new PC, when trying to update iPod Mini, keep getting error message:
    "Attempting to copy to the disk "SUSIE'S IPO" failed. The disk is locked and cannot be written to".
    What am I doing wrong?

    Welcome to Apple Discussions!
    First off, make sure everything is updated...
    http://www.apple.com/ipod/download
    http://www.apple.com/itunes/download
    Now see if restoring your iPod helps...
    http://docs.info.apple.com/article.html?artnum=60983
    btabz

  • How to use Optimistic Locking in Toplink

    Hi!
    Iam using Toplink for O/R mapping, and for each table
    iam using one TimeStamp field, and i specified that
    field as Locking filed, by using the Loking option, and checked the TimeStampLocking option.
    Now my question is do i need to update the Timestamp filed
    each time if i create a new record and while modify an existing record.
    And also do i need to compare the Timestamp for the record which client as read previousley to the TimeStamp in the database for the record manullay lik
    suppose t1 is the timeStamp, which i got from the client,
    and t2 is the timestamp which i read from the Database.
    Now my question is, is it necessary to compare the timestamp.

    Once optimistic locking has been configured TopLink will manage the updating and comparing of the OptimisticLocking value. There is no requirement for you to manage this value.
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for