|
Hi,
thank you for reading (and helping :-)) this!
i activated the version-checking in every table.
When two application-instances use the same dataset at the same time it correctly throws a StaleObjectStateException to the last user who saves changes to that dataset.
The question is: How can i react to this exception?
I thought about throwing away the changes the user did with a session.Refresh(...) that object.
After the Refresh the object has the actual values of the database and also the newest version number.
BUT: When I Flush the Session again, I also get an StaleObjectStateException again?!? WHY?
I use FlushMode.NEVER.
Please look at the code an give me a hint.
[Test]
public void VersionIstNachRefreshAktuell() {
//Installs some test data
int id = BeispielmandantenEinspielen();
//
ISession session1 = pHelper.OpenSession();
Mandant manSession1 = session1.Get<Mandant>(id);
ISession session2 = pHelper.OpenSession();
Mandant manSession2 = session2.Get<Mandant>(id);
Assert.AreEqual(manSession1.Version, manSession2.Version);
//change a value
manSession1.Praefix = manSession1.Praefix + "Geändert";
Assert.AreEqual(manSession1.Version, manSession2.Version);
session1.Flush();
Assert.AreNotEqual(manSession1.Version, manSession2.Version);
//change same dataset in different session
manSession2.Praefix = "WasAnderes";
//session2 can´t save (this exception is correct)
bool exceptionAutgetreten = false;
try {
session2.Flush();
} catch(StaleObjectStateException) {
exceptionAutgetreten = true;
}
if (!exceptionAutgetreten) {
Assert.Fail("StaleObjectStateException did not occure.");
}
session2.Refresh(manSession2);
Assert.AreEqual(manSession1.Version, manSession2.Version);
Assert.AreNotEqual("WasAnderes", manSession2.Praefix);
Assert.AreEqual("objectGeändert", manSession2.Praefix);
//session2 user tries again changing the dataset on the actual data
manSession2.Praefix = "WiederWasAnderes";
session2.Flush();
//again a StaleObjectStateException --- WHY??????
}
Hibernate version:
1.2.0 GA
Name and version of the database you are using:
MSSqlserver 2005
Thanks for your help.
hiaso
|