Source Code: https://bitbucket.org/twleader59/orm
前兩篇討論的是 insert,對於許多 xml tag 的屬性也沒有多作說明,這一篇開始逐項的補充。(在開始說明前,先為每個 class 加上 toString(),以輸出欄位值。)
在之前 xml 設定中 set tag 有個屬性 lazy,通常我們會將它設定為 true,表示會延遲下載,那麼有沒有延遲下載有什麼差別? 看一下下面這段程式:
1 Customer c = session.load(Customer.class, "2000000025");
2
3 if (c == null) {
4 System.out.println("customer is null");
5 }
6 else {
7 System.out.println(c.toString());
8 //System.out.println(c.getSales().toString());
9 //System.out.println(c.getGoods().toString());
10 }
(在 hibernate.cfg.xml 中加入 <property name="show_sql">true</property> 即可輸出 sql)
Hibernate:
select
customer0_.CID as CID1_0_0_,
customer0_.NAME as NAME2_0_0_,
customer0_.EMNO as EMNO3_0_0_
from
STEVEN.CUSTOMER customer0_
where
customer0_.CID=?
Hibernate:
select
customer0_.CID as CID1_0_0_,
customer0_.NAME as NAME2_0_0_,
customer0_.EMNO as EMNO3_0_0_
from
STEVEN.CUSTOMER customer0_
where
customer0_.CID=?
Hibernate:
select
goods0_.CID as CID1_2_0_,
goods0_.GID as GID2_2_0_,
goods1_.GID as GID1_1_1_,
goods1_.NAME as NAME2_1_1_
from
STEVEN.ORDERS goods0_
inner join
STEVEN.GOODS goods1_
on goods0_.GID=goods1_.GID
where
goods0_.CID=?
Hibernate:
select
customer0_.CID as CID1_0_0_,
customer0_.NAME as NAME2_0_0_,
customer0_.EMNO as EMNO3_0_0_
from
STEVEN.CUSTOMER customer0_
where
customer0_.CID=?
Hibernate:
select
goods0_.CID as CID1_2_0_,
goods0_.GID as GID2_2_0_,
goods1_.GID as GID1_1_1_,
goods1_.NAME as NAME2_1_1_
from
STEVEN.ORDERS goods0_
inner join
STEVEN.GOODS goods1_
on goods0_.GID=goods1_.GID
where
goods0_.CID=?
Hibernate:
select
sales0_.EMNO as EMNO1_3_0_,
sales0_.NAME as NAME2_3_0_
from
STEVEN.SALES sales0_
where
sales0_.EMNO=?
沒有留言:
張貼留言