openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shoevarek <>
Subject Auto generation of the WHERE clause
Date Tue, 19 Feb 2013 04:23:46 GMT

Our application talks to DB2 9.7 database. We looked at implementing
optimistic locking using JPA version fields, however for multiple reasons
(many other systems accessing database) we would prefer to enforce
optimistic locking within database itself. So far we looked at following

1) Implement listener on preUpdate entity lifecycle event which will update
entity version field (numeric field) on entity update. Such field would
store version value but would not be annotated as version field. That would
ensure that such field will be added to generated update statement but its
old value would not be used in the where clause of the generated statement.
In the database we would have trigger that would compare version field value
in the update statement with current version value in a table row and throw
exception if optimistic locking scenario is identified.

2) Define our entities to contain field that stores DB2 row change token.
Each update statement executed by our application would need to contain
WHERE clause comparing row change token value with one kept in entity. DB2
would throw the exception if no rows is identified by such filter (e.g. when
row change token changed due to row update by other transaction). This
solution would depend on Db2 optimistic locking mechanism.

The second approach could only work if we found the way of appending WHERE
clause to every update statement generated by JPA provider. Is there a way
to implement such component by extending any OpenJPA API? Such component
would need to have access to the state of the entity that is about to be
updated in the database (in order to get row change token value) and have
access to the query object in order to add or modify WHERE clause.


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message