Hibernate:如何表示这种类型的关系

时间:2018-03-11 14:47:38

标签: mysql hibernate jpa

我正在尝试在旧版DB上添加hibernate。我有下面的架构。

       X_Table
+--------+-----------+
| number |  class_id |
+--------+-----------+
|      1 |  c1       |
|      1 |  c2       |
|      1 |  c3       |
|      2 |  c2       |
|      2 |  c4       |
|      3 |  c4       |
|      4 |  c5       |
+--------+-----------+


                   Y_Table
+----+-------------+-------------+------------+
| id |  class_id_1 |  class_id_2 |  other_col |
+----+-------------+-------------+------------+
|  1 | c1          | c2          |  value1    |
|  2 | c1          | c3          |  value1    |
|  3 | c2          | c3          |  value1    |
|  4 | c3          | c5          |  value1    |
|  5 | c3          | c4          |  value1    |
+----+-------------+-------------+------------+

如何在Hibernate中映射这些表?

这是用于获取数据的当前查询

SELECT *
FROM Y_Table AS Y
    LEFT OUTER JOIN X_Table AS X
        ON Y.class_id_1 = X.class_id
    LEFT OUTER JOIN X_Table AS X2
        ON Y.class_id_2 = X2.class_id

0 个答案:

没有答案