20030421 Monday April 21, 2003

Locking Records in Webapps Our tester, Roberto, started working at my day job today. This means that I've been hacking and interacting with Bugzilla all day. It's great to have someone to validate our code meets the requirements (BTW, all our requirements are kept in Bugzilla - how's that for dynamic requirements?!) So, as far as satisfying my desire to be a productive American, today has been a good day. After I ride home (~20 miles) tonight, I'll feel on top of the world. Anyway, back to the point of this post.

One of the bugs that Roberto entered was that a user could login using two separate browser sessions (same user), and blah, blah, blah. I'm sure anyone who's worked with webapps has seen this. You open a page up in both browsers, click "Save" in the first, and then "Save" in the second. The second browser overwrites the first one's changes. I've seen this bug many times, but I've never solved it, nor even tried.

I'm curious to know if any of you have solved this? I think Hibernate has a way of locking an object - but will that solve this issue? I'm willing to implement a quick solution, otherwise, I'll argue the bugs validity until I'm blue in the face. Hmmm, I wonder if I can simply use Struts' Tokens feature to solve this problem? Please hook me up if you've solved this problem in your webapps. Posted in Java at Apr 21 2003, 05:07:24 PM MDT 4 Comments

Comments:

I am new to Hibernate too, so I have not tried this yet. I think Hibernate can help with the use of versioning. You can get Hibernate to add a version column to your tables and it will track them. When someone tries to upate the record the version will be checked to see it matches, if not someone must have updated the record. There is an example here: http://hibernate.bluemars.net/hib_docs/reference/html/transactions.html I believe the Struts Tokens will stop people submitting the same data twice (such as pressing refresh or clicking back and submitting again), in the same session. If the other browser had it's own session you would still have the same problem.

Posted by Jason Lea on April 21, 2003 at 05:35 PM MDT #

Well, that didn't take long... I have had a play with struts-hibernate example that Ted Husted created here http://sourceforge.net/projects/struts/ In ContactList.execute() add the following to the try/catch/finally block: } catch (StaleObjectStateException e) { //do something here } Hibernate throws the StaleObjectStateException when the version numbers don't match. I can then add an error message or forward to a failure page etc

Posted by Jason Lea on April 21, 2003 at 06:09 PM MDT #

Easiest way is to make all the updated fileds a part of the where clause (and flush the cache). The "other" way of a timestamp field is not as good. hth, .V

Posted by Vic on April 22, 2003 at 05:31 AM MDT #

>> Easiest way is to make all the updated fileds a part of the where clause Slooowwww. >> The "other" way of a timestamp field is not as good. There are TWO other ways! timestamp field (not quite as safe) version number field (the best) Hibernate supports both <timestamp> and <version> mappings.

Posted by Gavin on April 23, 2003 at 06:56 PM MDT #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is the Lead UI Architect at LinkedIn. The opinions on this site are mine, not my employers.
« November 2008
SunMonTueWedThuFriSat
      
1
2
3
6
7
8
9
10
11
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      
Today

Recent Entries

Tag Cloud