[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] (Newbie)Optimistic Locking for Web Apps
|
tch wrote:
>
> Just for future people, why don't you let us know what you missed?
>
I'm using the Struts 2 framework which will "automagically" create a new
instance of the entity for me. I ommitted to include the version number as a
hidden field on the form to return to the framework, so Struts 2 just gave
it the default value which is insufficient to trigger the optimistic
locking. Once I added the version attribute to the html form, optimistic
locking works like a charm - it's actually embarassingly easy to implement!
So in summary;
1) Add the version number field to your database table.
2) Add the version annotation to your entity.java
3) Include the version number as a hidden field in your html data entry form
and return it with the update request.
4) Create a new Entity instance with the returned data (this is the bit that
Struts does for you)
5) EntityManager.merge(entity)
Regards
--
View this message in context: http://www.nabble.com/%28Newbie%29Optimistic-Locking-for-Web-Apps-tp25381983p25383006.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.