Hibernate version: 2.1.6
I'm mapping a Bi-directional Many-To-Many and have Hibernate generate the tables via schema update. I'm a bit confused though. Hibernate is only creating one foreign key reference on the table that's used to map the relationship. Here are the mappings slimmed down the important parts:
Code:
<class
name="com.foo.user.business.BusinessRole"
table="BUSINESS_ROLE"
>
<id
name="roleId"
column="ROLE_ID"
type="int"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>
<set
name="users"
table="BUSINESS_USER_ROLE_MAP"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
column="role_id"
>
</key>
<element
column="user_id"
type="com.foo.user.business.BusinessUser"
not-null="false"
unique="false"
/>
</set>
</class>
<class
name="com.foo.user.business.BusinessUser"
table="BUSINESS_USER"
>
<id
name="userId"
column="USER_ID"
type="int"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>
<set
name="roles"
table="BUSINESS_USER_ROLE_MAP"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="user_id"
>
</key>
<element
column="role_id"
type="com.foo.user.business.BusinessRole"
not-null="false"
unique="false"
/>
</set>
</class>
It creates good BUSINESS_USER and BUSINESS_ROLE tables, it's the BUSINESS_USER_ROLE_MAP table that isn't what I thought it would be.
BUSINESS_USER_ROLE_MAP only has NOT NULL on USER_ID, but not ROLE_ID. In addtion, USER_ID has a foreign key reference back to BUSINESS_USER, but there is no foreign key reference for ROLE_ID. Why is this? I would think ROLE_ID would get NOT NULL and a foreign key reference as well.
Any ideas?
Thanks,
Patrick