You seem to have "constrained" at both ends of the relationships, it should only be on the dependent entity (Employee and BankAccount)
Current: (user) <one-to-one name="Employee" cascade="all-delete-orphan" constrained="true" foreign-key="none" /> (employee) <one-to-one name="User" constrained="true" /> Try dropping the 'constrained' attribute from the <one-to-many>'s in User /Pete From: [email protected] [mailto:[email protected]] On Behalf Of Marcello Esposito Sent: 30 January 2013 17:15 To: [email protected] Subject: [nhusers] NHibernate pure one-to-one mapping Hi all. I'm trying to create a one-to-one NHibernate mapping between three entities (in my actual scenario entities are much more): User | +--Employee | +--BankAccount For each User there is exactly one Employee and exactly one BankAccount. These are my mappings. <class name="User" table="Users"> <id name="Id"> <generator class="guid.comb" /> </id> <property name="Name" not-null="true" /> <one-to-one name="Employee" cascade="all-delete-orphan" constrained="true" foreign-key="none" /> <one-to-one name="BankAccount" cascade="all-delete-orphan" constrained="true" foreign-key="none" /> </class> <class name="Employee" table="Employees"> <id name="Id" column="IDUser"> <generator class="foreign"> <param name="property">User</param> </generator> </id> <property name="HireDate" not-null="true" /> <one-to-one name="User" constrained="true" /> </class> <class name="BankAccount" table="BankAccounts"> <id name="Id" column="IDUser"> <generator class="foreign"> <param name="property">User</param> </generator> </id> <property name="AccountNumber" not-null="true" /> <one-to-one name="User" constrained="true" /> </class> This solution allows to target the following objectives: * Primary key for the three entities are the same (strict one-to-one relation). * Employees and BankAccounts tables have a foreign-key on Users table. * Loading a user does not join on other two tables and correctly creates a lazy-ready proxy (see famous Ayende post <http://ayende.com/blog/3960/nhibernate-mapping-one-to-one> ) Any other configuration I've tried misses some of the above points. The problem is that, while inserting a user into the DB, NHibernate inserts Employee and BankAccount before User, thus raising a foreign-key exception. Currently I am using foreign-key="none" on both sides of the relation, thus giving up on the referential integrity constraint. Any help about the correct way to address this mapping? Thanks. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers?hl=en. For more options, visit https://groups.google.com/groups/opt_out. !DSPAM:1,5109551f1871750812013! -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/nhusers?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
