Hibernate's
<idbag> facility allows you to map many-to-many associations and collections of values to a single table with a surrogate key. The following code shows an example of
<idbag> mapping:
<idbag name="cars" table="CARS">
<collection-id column="car_id" type="long">
<generator class="sequence"/>
</collection-id>
<key column="car_I"/>
<many-to-many column="car_II" class="Car" outer-join="true"/>
</idbag>
Done!