我正在尝试在旧版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