Hi all
I just implemented the "Open Session in View pattern" and am a bit concerned about data integrity.
Heres the scenario:
The object:
class Test
{
int Attribute1 = 0;
int Attribute2 = 0;
}
The flow:
1) Request 1 arrives and a new Session is opened for this request. The Action (were using struts) loads an the Test object and goes off and does some calculation
2) Request 2 arrives and a new Session is opened on another Thread for this request. The Action loads the same Test object sets Attribute1 to “2” and Attribute2 to “2” and saves the object.
3) Request 1 finishes the calculation modifies sets Attribute1 to “1” and saves the object.
The Problem/Question:
What’s in the Database?
Is it:
1) Sessions do not know of each other and request 1 and 2 get two completely separate instances of Test. This would mean that the last one who writes the object wins (in this case Request 1). This would result in a Test object in the DB with Attribute1 = “1” and Attribute 2 =”0”
2) Sessions know of each other and they get the same Object back which would result in Attribute1 = “1” and Attribute2 = “2”
3) Hibernate detects that two Sessions modified the same object and throws an exception.
4) ????
Could someone explain to me how it works.
Thanks a lot
Ralph
Code:
Code:
Code:
[quote][/quote]