Hello all,

On this scenario I simulate a series of WCF calls to NHibernate 
(OneSessionPerWCFCall). A total of 4 sessions are opened, 3 of them are in 
one transaction scope that at the end is supposed to rollback. The last one 
is in another transaction scope and gathers data from the 2nd level cache 
that was not correctly updated after rollback.

[TestMethod]
public void CacheTest() {
// create transaction (rollback at the end)
var comments = Guid.NewGuid().ToString("N");
using (new TransactionScope(TransactionScopeOption.Required, new 
TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) {
// request #1 - load
// open another session to force using 2nd level cache values
using (var session = MasterSessionFactory.OpenSession()) {
// create tx
using (var transaction = session.BeginTransaction()) {
// reload version
var entity = session.Get<SpecificVehicle>(358);
// assert 
Assert.IsNotNull(entity);
// commit
transaction.Commit();
}
}
// request #2 - publish
// open another session to force using 2nd level cache values
using (var session = MasterSessionFactory.OpenSession()) {
// create tx
using (var transaction = session.BeginTransaction()) {
// reload
var entity = session.Load<SpecificVehicle>(358);
// update
entity.Comments = comments;
// commit
transaction.Commit();
}
}
// request #3 - reload
// open another session to force using 2nd level cache values
using (var session = MasterSessionFactory.OpenSession()) {
// create tx
using (var transaction = session.BeginTransaction()) {
// reload version
var entity = session.Get<SpecificVehicle>(358);
// assert 
Assert.IsTrue(entity.Comments == comments, "The property was not updated");
// commit
transaction.Commit();
}
}
}
// request #4 - load after rollback
using (new TransactionScope(TransactionScopeOption.Required, new 
TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) {
// open another session to force using 2nd level cache values
using (var session = MasterSessionFactory.OpenSession()) {
// create tx
using (var transaction = session.BeginTransaction()) {
// reload version
var entity = session.Get<SpecificVehicle>(358);
// assert 
Assert.IsTrue(entity.Comments != comments, "The property was updated after 
rollback"); // THIS ASSERTION FAILS
// commit
transaction.Commit();
}
}
}
}

Here are listed the NHibernate profiler screen shots in order per opened 
session.
Session 1

<https://lh3.googleusercontent.com/-0E2Y0uPFgjI/UgD6tXs1FTI/AAAAAAAAAXE/9OUFnmgutmU/s1600/Session+1.PNG>
Session 2


<https://lh3.googleusercontent.com/-j0Y140xNCCk/UgD69YbZpZI/AAAAAAAAAXM/V9Rwam3Z8ts/s1600/Session+2.PNG>


Session 3

<https://lh3.googleusercontent.com/-2zEssnSR11A/UgD7OdVZFzI/AAAAAAAAAXU/44BVfGxHIZQ/s1600/Session+3.PNG>

Session 4


<https://lh3.googleusercontent.com/-fj688Q1v4ac/UgD7bmTMQPI/AAAAAAAAAXc/epFXf8M15zw/s1600/Session+4.PNG>


The second level cache works properly as can be seen in the NH profiler, 
but when the first transaction scope is disposed it rolls back changes from 
all the inner transactions it contains, but still for the new scope which 
get the values from the cache, values where not rolled back.




-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to