Have spent a few hours searching for information on this problem but no luck.
So let's say you have a base class User with a primary key column named "id". Following the table-per-subclass hierarchy, you create another class called Student with a primary key of "user_id". So "user_id" would be also be the foreign key to the "id" field of the User class. So your two database tables are set up the same with value-generation on the "id" field of User. So now you create your mapping files with the subclass in its own file. The mapping for User would now look like:
Code:
<hibernate-mapping>
<class name="...User" table="USER" schema="..whatever">
<id name="id" type="...Integer">
<column name="ID" />
</id>
....properties...
</class>
</hibernate-mapping>
And your Student mapping would be:
Code:
<hibernate-mapping>
<joined-subclass name="...User" extends="...User" table="STUDENT" schema="..whatever">
<key column="USER_ID"/>
....properties...
</joined-subclass>
</hibernate-mapping>
On save, Hibernate should be smart enough to create and insert the super-class User object first, then take the generated id from its "id" column and insert into "user_id" specified in the Student's <key> tag column. Well for some odd reason, it only works IF the two columns have the same name. In this case, in the Student mapping file, it would have to be <key column="ID">. Also, the Student table in the database also has to have the primary/foreign key column named the same as the User tables primary key, so "USER_ID" needs to be renamed to "ID". There is no documentation on this issue. Nowhere can I find something that says these columns must be named the same. I've tried multiple variations and none have worked. I keep getting "id is required to load" exceptions and I can see by the query that the insert statement for Student includes an "ID" column instead of "USER_ID".
Has anyone else experienced this issue? Anybody know anything about this? I believe this is Hibernate 3 something.