NHibernate stateless session – What is the data alias?

NHibernate documents applicable to stateless session interface states, including:

Stateless sessions are vulnerable to < strong>data aliasing effects, due to the
lack of a first-level cache.

I can’t find an explanation. What does’data aliasing effects’ mean?

If you can give an example… that’d be great.

Consider the following example

table Orders
id | customer_id | quantity
--------- ------------------
1 | 1 | 5
2 | 1 | 20


var orders = statelessSession.Query().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( ).ToList();
orders[0].Customer.HasDiscount = true;
Assert.True(orders[1].Customer.HasDiscount);

So, use none State session, the customer is not the same instance, so the update cannot be seen, and ReferenceEquals will return false. You have two aliases for the same customer

Suitable for stateless session interface state NHibernate documentation, which includes:

Stateless sessions are vulnerable to data aliasing effects, due to the
lack of a first-level cache.

I can’t find a solution Explanation. What does ‘data alias effect’ mean?

If you can give an example… that’d be great.

Consider the following example

table Orders
id | customer_id | quantity
--------------------- ------
1 | 1 | 5
2 | 1 | 20


var orders = statelessSession.Query().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().ToList();
orders[ 0].Customer.HasDiscount = true;
Assert.True(orders[1].Customer.HasDiscount);

Therefore, when using stateless sessions, customers are not the same instance, so they cannot be viewed To update, and ReferenceEquals will return false. You have two aliases for the same customer

Leave a Comment

Your email address will not be published.