Hibernate - 具有额外列的N - N表的XML映射 [英] Hibernate - XML Mapping of a N<->N Table with extra columns

查看:123
本文介绍了Hibernate - 具有额外列的N - N表的XML映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个模式:

I have this schema:

---------------  --------------------  ----------------
| Customers   |  | CustomRoutePrice |  | Route        |
|-------------|  |------------------|  ---------------|
| CustId (pk) |  | CustId  (pk)     |  | RouteId (pk) |
| Desc        |  | RouteId (pk)     |  | Desc         |
---------------  | Price            |  | Price        |
                 --------------------  ----------------

我想将 CustomRoutePrice 的价格映射到我的客户的POJO,如下所示:

and I want to map the CustomRoutePrice's Price to my Customers POJO, saying something like:

Map<Route, Double> customRoutesPrices;

或者可能有一个新的POJO叫做 CustomRoute ,所以它可能看起来像这样:

or maybe having a new POJO called CustomRoute, so it may look something like this:

public class CustomRoute {
    private Customer customer;
    private Route route;
    private Double price;
}

所以在 Customer > s POJO我可以有一个像这样的集合:

so within my Customers POJO I could have a set like:

Set<CustomRoute> customRoutes;

可能是 CustomRoute s的集合对于 Customer

which may be the set of CustomRoutes for that Customer.

所以我的问题是如何使两个映射成为可能?

So my question is how can I make possible both mappings?

预先感谢您。

Thank you in advance.

推荐答案

您可以声明Map< Route,Double>:

You can declare a Map<Route,Double>:

<map name="customRoutesPrices" table="CustomRoutePrice">
  <key column="CustId" not-null="true"/>
  <map-key-many-to-many class="Route" column="RouteId"/>
  <element column="Price" type="double"/>
</map>

这篇关于Hibernate - 具有额外列的N - N表的XML映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆