Read-only object with unidirectional one-to-many and many-to-many

Skip to first unread message

Scott Korin

Jun 20, 2020, 1:19:26 PM6/20/20
to nhibernate-development
The NHibernate documentation clearly states that  "NHibernate treats unidirectional one-to-many and many-to-many associations owned by a read-only entity the same as when owned by an entity that is not read-only."

My question is:  Why?

If I loaded an object as readonly, I would expect all of its collections to be readonly and not dirty checked.  Why did nHibernate decide to not implement it this way?

I ask this because a of a project I've inherited has issues with unnecessary SELECT statements happening when a session transaction closes.  I discovered this was because the object in question had a lot of child collections where the getter called a function on the underlying data (self-changing entities) to mitigate an issue where nhibernate inserts null objects into lists with a sequence field where there's a gap in the sequence.  I understand the right way to fix this is to not to call a function on the getter, but I was trying to avoid that by calling the parent object as read-only.

But also, in these cases, I know I am only loading the parent object to access data and I am not changing it.  I don't need NHibernate to check if it's dirty, I know it's not, similar to using AsNoTracking() in Entity Framework.

So, back to the question:  Why was NHibernate implemented this way?
Reply all
Reply to author
0 new messages