kpanghmc ,
Quote:
1. Bidirectional - each User object is aware of all the Addresses it has and each Address object is aware of the User object it belongs to.
2. Unidirectional - each User object is aware of all the Addresses it has, but each Address object is ignorant of which User it belongs to.
Your characterization of unidirectional and bidirectional is correct.
Quote:
1. Does the "UserID" column in the "Addresses" table have to be nullable in order to support this? It seems that NHibernate is performing a save before an update to this table when saving off a User, which ends up saving a null into the UserID column before updating it.
That depends on your business model, specifically, if addresses can exist as as independent entities, not related to any particular User.
If they cannot, you can set the FK to not-null, and Hibernate will have to insert in one step.
Notice that this has nothing to do with the relationship being unidirectional or bidirectional.
I also remind you also, that NULL is, in SQL terms, a valid value for FK fields.
Quote:
3. Do each of the Address objects have to store a UserID in order for this relationship to work? I assume so, otherwise if I were to call Save on an Address object, it wouldn't know what to write to the UserID column.
The child object does not have a "userId" property.
If the relationship is unidirectional, it has nothing.
If the relationship is bidirectional, it holds a reference to the whole parent (a User object), not just its id.