Everything seems to work just nicely once I remove the foreign key constraint from the database. I can insert different IDs into the same column based on the subclass used and select them out (in a new session) with no problems.
It's a shame there isn't an attribute in the many-to-one relationship that instructs SchemeExport to skip foreign key constraint creation. I am writing an application in which the user is able to create as many databases as they want (MSAccess or SQLite files) and I'd rather not have to write special code to remove constraints (especially since they seem to named randomly).
Getting back to my original requirement of having an object property rather than subclasses with typed properties, I also tried specifying subclasses as the same type as the parent. Now obviously the discriminator field couldn't be automatically filled during an insert as the subclass type would usually indicate the discriminator value to be stored. So I tried setting up a property for the discriminator and manually filling it, but unfortunately this approach didn't work.
Anyway, thanks for the help. I'll be creating a subclass for all the different tables that I may need to reference.
Here is my test hbm:
Code:
<class name="Event">
<id name="ID">
<generator class="uid" />
</id>
<discriminator column="ParentType" />
<subclass name="CarEvent" discriminator-value="Car">
<many-to-one name="Parent" column="ParentID" />
</subclass>
<subclass name="HorseEvent" discriminator-value="Horse">
<many-to-one name="Parent" column="ParentID" />
</subclass>
</class>
<class name="Car">
<id name="ID">
<generator class="uid" />
</id>
<property name="Name" />
</class>
<class name="Horse">
<id name="ID">
<generator class="uid" />
</id>
<property name="Name" />
</class>