Hibernate: many-to-any mapping

Why

Convenient for a collection of objects implementing the same Java interface.

Code

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.

Reference

 
write a message
Name


City


Email (won't be displayed)




Antispam: enter the current year (2008)