0
我在我的數據庫中的表結構:Java的休眠標準
Table A: Table B: Table C:
_______________________ ______________________________ ______________________
| Field | Type | Key | | Field | Type | Key | | Field | Type | Key |
______________________| |_____________________________| |_____________________|
| a_id | Int | PRI | | a_id | Int | FK of A(a_id)| | c_id | Int | PRI |
| ... ... | | c_id | Int | FK of C(c_id)| | ... |
|_____________________| ______________________________ |_____________________|
和對象:
class A {
List<C> list;
...
}
現在我想從數據庫中的所有C對象接收對象的由表B組合。我有準則接收正確的對象A,但我不知道如何接收相應C對象的列表:
Criteria crit = ...;
A a = crit.uniqueResult();
這裏是SQL查詢,讓我正確的結果和現在應該被「翻譯」的標準:
select c.*
from A as a,
B as b,
C as c
where a.a_id = b.a_id and b.c_id = c.c_id;
有誰知道如何制定標準是什麼?
您是否嘗試過使用HQL而不是Criteria API?你的實體是怎樣的? –
所有其他數據庫訪問都使用Criterias完成,因此我想堅持這一點;我添加了可以工作的SQL查詢,並且應該在Criteria中對其進行「翻譯」 – wasp256