質問

I find it hard to believe that I am the only one wondering about the proper way to implement this but unfortunately my search didn't return any good solution.

Basically we have web apps implemented using spring mvc and hibernate. Since it is a MVC model that points to jsp pages, we loose the object after fulfilling a request and then we reconstruct from the ID before doing the update.

What would be the best way to re-design this with concurrency in mind? (right now we don't take concurrency into account!!) Yes, we can save the version as a hidden field in the JSP and send it in the post request, but that doesn't seem to be an "elegant" solution. Is there a better way?

役に立ちましたか?

解決

The problem is discussed in the hibernate documentation, in the section about optimistic concurrency control. You can use a session which stays open for the duration of a whole conversation (without keeping a database connection open, of course). I think this is the strategy adopted by JBoss Seam, although I've never used it (nor did I use this session-per-conversation strategy).

If you want to keep it simple, storing the version field in a hidden field or in a session attribute is indeed the only solution I see.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top