users@glassfish.java.net

Re: The OptimisticLockException is related to Session Cache of Toplink Essentials

From: Wu Jie <wujie_at_cn.fujitsu.com>
Date: Tue, 17 Mar 2009 17:06:20 +0800

Hi Peter
Hi GF) Dev Teams,
Hi Everyone,

Sorry for recalling this issue, and I also filled it into java.net.
https://glassfish.dev.java.net/issues/show_bug.cgi?id=7362

I am eager for someone's response. and appreciate ahead.

Thanks.
-Wu

Wu Jie さんは書きました:
> Hi Peter
> Hi GF) Dev Teams,
> Hi Everyone,
>
> I encountered OptimisticLockException when running JPA app wich
> enables session cache. I looked into the runtime and found that
> the cause of OptimisticLockException seems to be related to the
> session cache. and when I disabled session cache the app ran
> successfully.
>
> The app I used is attached. and steps of exception repoduction
> is following.
> =======================================================================
> 1. asadmin start-database
> 2. asadmin start-domain
> 3. asadmin deploy --retrieve . sample-ear.ear
> 4. appclient -client sample-earClient.jar create-role testrole
> 5. appclient -client sample-earClient.jar create-user testuser testrole
> 6. appclient -client sample-earClient.jar get-user testuser
> 7. appclient -client sample-earClient.jar delete-user testuser
>
> Test env:
> - Windows
> - JDK 6 Update 4
> - GlassFish V2 UR1 b09d
>
> JDBC Resource: "Jdbc/__default" of GF by default.
> =======================================================================
>
> It seems that the entity verison of step 5 is difference from the one
> of step 6, so when execute step 7 OptimisticLockException occured.
>
> In my opinion the exception cause is following.
> Exception Patern :
> 1. Transaction Begin
> 2. Entity Persist
> 3. EntityManager.flush()
> 4. Entity Update
> 5. Tranction End(commit)
> 6. Read and Update for the same Entity in other Transaction
>
> The update of step 4 is committed to database in step 5. because
> the entity of step 4 is the same to the one in the session cache
> which is produced by step 3, the result of step 4 does not update
> the session cache(the old version remains in session cache). so
> when step 6 obtains the entity in seesion cahce and update it
> OptimisticLockException occurs.
>
> [How To Avert OptimisticLockException]
> there are 3 ways following.
> A. Before step 6, invoking EntityManager.refresh().
> B. Using TopLink-specific refresh hint When executes step 6
> C. Disable session cache
>
> Is there any other ways to avert the OptimisticLockException ?
> Could you please give me some suggestion or comment and any help
> is appreciated.
>
> Thanks
> -Wu
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net


-- 
 ----------------------------------------------------
 Wu Jie
 Development Dept.II
 Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
 8/F., Civil Defense Building, No.189 Guangzhou Road,
 Nanjing, 210029, China
 TEL: +86+25-86630566-956
 COINS: 79955-956
 FAX: +86+25-83317685
 Mail: wujie_at_cn.fujitsu.com
 ----------------------------------------------------
 This communication is for use by the intended recipient(s) only and may
 contain information that is privileged, confidential and exempt from
 disclosure under applicable law. If you are not an intended recipient of
 this communication, you are hereby notified that any dissemination,
 distribution or copying hereof is strictly prohibited. If you have
 received this communication in error, please notify me by reply e-mail,
 permanently delete this communication from your system, and destroy any
 hard copies you may have printed.