0

有 3 个表OrderProductOrderProductMapping表 只有 2 个实体类:和Order表共享关系。这意味着一个订单可以有多个产品,一个产品可以属于多个订单。为了映射这个,有第三个表名为Product OrderProductmany-tomanyOrderProductMapping

下面是我的order.hbm文件映射

<set name="product" table="OrderProductMapping">
    <key column="orderId"/>
    <many-to-many class="Product">
        <column name="productId" />
    </many-to-many>
</set>

下面是来自product.hbm文件的映射

<set name="order" table="OrderProductMapping" inverse="true">
    <key>
        <column name="orderId"/>
    </key>
    <many-to-many class="Product">
        <column name="productId" />
    </many-to-many>
</set>

现在我需要在映射表中引入一个新列应该如何进行?任何帮助或指示都会很棒。

4

1 回答 1

0

创建一个新实体 OrderProductMapping,然后将 @ManytoMany 替换为双向 @OneToMany Order > OrderProductMapping < Product。

也可以看看:

Hibernate 最佳实践:避免多对多和“奇异​​”关系

于 2013-10-10T15:09:44.327 回答