1. 程式人生 > >hibernate多表關聯的簡單寫法

hibernate多表關聯的簡單寫法

1.這是普通的mysql 三表關聯的果詢語句

select p.* from category c,categorysecond cs,product p where c.cid = cs.cid and cs.csid = p.csid limit 0,1;

2.用hibernate 的hql語句,可以這樣寫

select p.* from Category,Categorysecond ,Product  where Category.cid =Categorysecond.Category.cid   and   Categorysecond.csid = Product.Categorysecond.csid;

3,還有一種簡單的方法,它會根據各個表中的關聯的欄位自己進行關聯。

select p.* from   Product p  join  p.Categorysecond  cs  join   cs.Categroy   c;