Ciao,
I don't understand exactly your domain model and the classes envolved, but I think that if there is like you said a one-to-one relation between the two of them, then you should map in both of the classes the referenced property like a one-to-one relation.
Bellow I inserted a example of how I map the one-to-one ralation in two tables that I used and works in NHibernate:
Let's say you have two tables:
Person where you have some Personal Information and another table with
Details. In the Person class you have a reference to a Detail object, that can also be NULL in some casses, and both Person and Detail tables have the same primary key. When I map, I put in both of the mapping files the relation as one-to-one like this:
In Person:
Code:
<one-to-one name="Detail" class="Detail" cascade="none" fetch="join"/>
In Detail:
Code:
<one-to-one name="Person" class="Person" cascade="none" fetch="join"/>
And on the Person class you have a property of type Detail (that can be NULL) and on the Detail you have a property of type Person.
I hope this will give you a clear ideea of the use of one-to-one relation.
And when you want to get only the Persons that have a Detail you can use this code:
Code:
ICriteria criteriaPerson=session.CreateCriteria(typeof(Person));
ICriteria criteriaDetail=ctiteriaPerson.CreateCriteria("Detail",NHibernate.SqlCommand.JoinType.RightOuterJoin);
IList listWithOnlyThoseWhoHaveDetail=criteriaPerson.List<Person>();
If you want all Persons with or without Detail you simply have to change the JoinType to LeftOuterJoin.
Good luck my friend! Hope this helps!