On one of the projects I work on I came across the need to use a function to calculate a property value.
The basic functionality is well documented in the online docs, however it doesn’t explicitly say what happens if the function returns DB PK (id) and you want it mapped to a class. It’s not even matter of "formula" as it is general matter of mapping.
Normally mapping to a class is done with <many-to-one> element, but that element doesn’t support "formula" attribute, nor does it have <loader> element.
Simple test shows that it works if you simply specify the "formula" and the "type" attributes. Apparently it works almost like many-to-one, with one notable difference: if value is null, many-to-one assigns null, while property seems to assign a new uninitialized instance. I can live with that.
All hail nhibernate!
UPDATE (May 9 ’08):
Lots of hits on this page, so I’ve expanded on the topic: