我有4個表CustomerEntity,CustomerMaster,請求和UserMaster
和具有以下表的結構,如何在Hibernate中連接多個表?
CustomerEntity (id,address,branch,branch_id,city,entity_status,request_id,user_master_id)
CustomerMaster (id,customer_name,customer_type)
UserMaster(id,customer_master_id,employee_id,unique_id,employee_id)
Request(id,customer_master_id,parent_request_id,request_status,user_master_id)
當我正在做一個查詢從休眠這樣
sb.append("select c from CustomerEntity c, Request r ")
它提供我正確的數據,我需要,但現在有一種情況下,我需要捕獲UserMaster ID以及CustomerMaster ID值,這隻能通過加入UserMaster和CustomerMaster表與現有的查詢來獲取,但我'我不知道我在哪裏將獲得所有預計的數據,如上述查詢我收到'c'的數據,但在新的查詢中,我希望在加入所有這4個表後執行查詢中的所有值。
我使用下面的查詢:
sb.append("select * from (CustomerEntity as c join Request as r
on r.id = c.request_id)
left join CustomerMaster as c1 on r.customer_master_id = c1.id
left join UserMaster as u
on r.customer_master_id = u.customer_master_id");
在Hibernate這樣
,但它似乎沒有工作。