Wrong NHibernate.NonUniqueObjectException with readonly property

Description

I have a computed (getter only) property (its entity type of object with ID) on my model which I want to persist to database, mapped with

Saving my model to databse works well, but reading results in "NHibernate.NonUniqueObjectException".

This happens because NH loads a readonly property from DB in its cache, even if it doesnt going to use it and call model setter to assign read value. And then when read transaction ends it flushes the session, and for some reason decided to do UPDATE (my guess - NH checks readonly property, detects reference change and decides to update). During update I noticed that the computed Entity reference in session cache doesn't match entity reference returned by computer property (and of course it doesnt cause computed getter always return new object).

So I think this behavior of NH is incorrect in multiple spots.
1. Why put in session cache - entity of readonly property.
2. Why consider entity returned by computed property not the same as before. It overrides GetHashCode and Equals, and logically objects are the same, only reference are different.
3. Why do update when I only read data from DB (this is result of 2 I guess).

Environment

None

Activity

Show:
BrokenP
June 15, 2016 at 5:36 PM

Calculated properties feature was implemented in https://nhibernate.jira.com/browse/NH-1621.

Details

Assignee

Reporter

Components

Priority

Who's Looking?

Open Who's Looking?
Created June 15, 2016 at 5:20 PM
Updated June 15, 2016 at 5:36 PM
Who's Looking?