The NHibernate documentation for the stateless session interface states, among others:
Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.
I couldn't find an explanation for this. What does 'data aliasing effects' mean?
If you could give examples... that'd be great.
consider the following example
table Orders
id | customer_id | quantity
---------------------------
1 | 1 | 5
2 | 1 | 20
var orders = statelessSession.Query<Oders>().ToList();
orders[0].Customer.HasDiscount = true;
Assert.False(orders[0].Customer == orders[1].Customer);
Assert.False(orders[1].Customer.HasDiscount);
// while
var orders = session.Query<Oders>().ToList();
orders[0].Customer.HasDiscount = true;
Assert.True(orders[1].Customer.HasDiscount);
so using stateless session the customers are not the same instance hence updates are not seen where they should and ReferenceEquals will return false. You have two alias of the same Customer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With