users@glassfish.java.net

Optimistic locking : unnecessary update statements generated

From: <glassfish_at_javadesktop.org>
Date: Wed, 04 Apr 2007 04:09:39 PDT

Dear all,

    i adopt, optimistic locking approach, to lock table record before update.
***this is because the entitymanager.lock..operation only support entity with
***_at_version field

In my application, it is needed to log all change (insert / update / delete) make to a table
,say employee table , by table trigger .
(i use database trigger to log the change as some day i maybe made change to the
table employee 's record by other query tool , e.g. isql, sqlplus etc....)

    i find that for every entitymanager.flush() called, EVEN THOUGH the entity
( say Employee) DO NOT CHANGE, an update sql statements are issued
(it just update the version field ONLY)
....

   many unnecessary update sql statements are issued.
 the situation getting worse when a business transaction involve updates to several
entities (each call entitymanager.flush() to ensure sql statement do send to database)

****[as i want to detect when, which step cause the transaction to fails and return a
****more meaningful message to user.

****if i don't use optimistic locking, every thing works fine, no unnecessary
****update sql statement generate.


   this behavior affect my database triggers

   is this a 'feature' of toplink essentials ?

   or is it a bug?

   how can i avoid multiple sql update statements issued?

   without optimistic locking, the only way is to use toplink essentials' proprietary hint
'toplink.pessimistic-lock' when reading the entity from database?


thank you very much
[Message sent by forum member 'imperfect' (imperfect)]

http://forums.java.net/jive/thread.jspa?messageID=211235