Given the table definition as-is:
Code:
CREATE TABLE CPM (
id SERIAL PRIMARY KEY,
category INTEGER NOT NULL,
product INTEGER NOT NULL
);
You would only be able to handle this using the <idbag> collection mapper:
Code:
<class name="Category" table="Categories" ...>
...
<idbag name="products" table="CPM" ...>
<collection-id column="ID" type="long">
<generator .../>
</collection-id>
<key column="category"/>
<many-to-many class="Product" column="product"/>
</idbag>
...
</class>
The reason is the PK constraint definition on CPM. Without that, you could map this in Hibernate using any type of <many-to-many>:
Code:
<class name="Category" table="Categories" ...>
...
<set name="products" table="CPM" ...>
<key column="category"/>
<many-to-many class="Product" column="product"/>
</set>
...
</class>