有3个表,Order表,Product表,OrderProductMapping表,只有2个实体类:Order和Product,Order和Product表共享一个many-tomany关系。这意味着一个订单可以有多个产品,一个产品可以属于多个订单。为了映射这一点,有一个名为OrderProductMapping的第三个表
下面是来自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>现在我需要在映射表中引入一个新的列,该如何处理?任何帮助或指点都会很棒。
发布于 2013-10-10 23:09:44
创建一个新的实体产品,然后将@ManytoMany替换为双向@OneToMany Order > OrderProductMapping < OrderProductMapping。
另请参阅:
Hibernate Best Practices: Avoiding Many-To-Many and 'exotic' relationships
https://stackoverflow.com/questions/19296809
复制相似问题