Hibernate version: 3.0.4
Name and version of the database you are using: Oracle 10g
Not sure how/why this works the way it works, but I think there has to be a simple solution within hibernate.
There are 3 objects involved:
- User
- Asset
- VideoAsset (joined-subclass of Asset)
All Asset objects are owned by a User.
Code:
<class name="Asset" table="Asset">
<id column="id" name="id" type="long" unsaved-value="0">
<generator class="native" />
</id>
<many-to-one name="user" column="user_id" class="User" />
<joined-subclass name="VideoAsset" table="Video_Asset">
<key column="id" />
</joined-subclass>
</class>
I would like to have sets of the concrete subclasses into User.
Code:
<class name="User" table="MyUser">
<id column="id" name="id" type="long" unsaved-value="0">
<generator class="native" />
</id>
<set name="videoAssets">
<key column="user_id" />
<one-to-many class="VideoAsset" />
</set>
</class>
But the above doesnt work because it looks for
user_id in the
Video_Asset table. In fact, when I use the above mapping with hibernate DB auto-gen, it creates a column
user_id in the table
Video_Asset. Then
User.getVideoAssets() only returns those assets that have the
Video_Assets.user_id set. (And saving a
Video_Asset sets the
user_id in the
Asset table.
Something like:
Code:
<class name="User" table="MyUser">
<id column="id" name="id" type="long" unsaved-value="0">
<generator class="native" />
</id>
<set name="videoAssets">
<key column="user_id" table="Asset" />
<one-to-many class="VideoAsset" />
</set>
</class>
But really, I would think that it would automatically look in the parent class for the key. *sigh*
Thoughts? Thank you.