I've got a problem and I'm guessing I'm not the first person to run into it. It's not a terribly complex problem, but I've put together some images and a test application to demonstrate it. This is happening with NHibernate 1.2.1 GA.
The root of the problem seems to be the way the <key> element inside a mapped collection is handled. I have the following object model and NHibernate mapping:
Class Diagram
Mapping Document
The issue is in the way NHibernate handles the Parent column for Charlie objects. This schema was generated by NHibernate:
Table Diagram
Generated SQL
Notice that Charlie table has a foreign key constraint to the Bravo table. This causes problems, as I now can't add Charlie objects to Alpha. Notice that the issue isn't only in how the Schema Export happens, but also the query there where I'm searching for all Charlies that are children of an Alpha, it uses the Parent column on the Charlie table.
Is there something I'm doing wrong? I've got an entity type in my application and almost every other entity in our application contains a collection of that type. I can't seem to figure out how to map that in NHibernate.
Also, here is the Visual Studio 2008 project I used to test this:
Project Zip File
Any help is greatly appreciated.