openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mario Ds Briggs <mario.bri...@in.ibm.com>
Subject Re: Auto generation of the WHERE clause
Date Tue, 19 Feb 2013 04:35:51 GMT
Approach 2 is available - see the @VersionStrategy
("com.ibm.websphere.persistence.RowChangeTimestampStrategy")

http://setgetweb.com/tech/WAS70/Database_generated_version_ID63.html

thanks
Mario



From:	shoevarek <vatermann@gmail.com>
To:	users@openjpa.apache.org
Date:	02/19/2013 09:53 AM
Subject:	Auto generation of the WHERE clause



Hello.

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
options:

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:
http://openjpa.208410.n2.nabble.com/Auto-generation-of-the-WHERE-clause-tp7582868.html

Sent from the OpenJPA Users mailing list archive at Nabble.com.




Mime
View raw message