Convenient for a collection of objects implementing the same Java interface.
Robot has a set of Animals. Animal is just an interface.
Robot.hbm.xml
<set name="animals" table="robot_animals"> <key column="robot_id"/> <many-to-any id-type="long"> <column name="animal_class" not-null="true"/> <column name="animal_id" not-null="true"/> </many-to-any> </set>
Note: not-null=“true” makes that the primary key is a composite key of the three columns.