| 硄盽匡ノ贺膥┯琈甮家Αぇ碞礚猭甅ノ贺家Α琘ㄇ薄猵眤临琌睼ノㄢ贺膥┯家Αㄒ睼ノ 膥
┯ - Table per class hierarchy 籔 膥┯
- Table per subclassノTable per class hierarchyよΑ盢 DefaultUser 琈甮T_USERτノTable per subclassよΑ盢PowerUser穝﹚竡妮┦琈甮T_Poweruser create table T_PowerUser ( id bigint not null, otherProperty varchar(255), primary key (id) ) create table T_USER ( id bigint not null auto_increment, userType varchar(255) not null, name varchar(255), someProperty varchar(255), primary key (id) ) alter table T_PowerUser add index id (id), add constraint id foreign key (id) references T_USER (id) 眤ㄏノ<join>夹乓ㄓ﹚竡ㄒ
<?xml version="1.0" encoding="utf-8"?> 纗ンㄒ Hibernate:
insert into T_USER (name, userType) values (?, 'Power') Hibernate: insert into T_PowerUser (otherProperty, id) values (?, ?) Hibernate: insert into T_USER (name, someProperty, userType) values (?, ?, 'Default') 琩高ㄒ Hibernate:
select user0_.id as id0_, user0_.name as name0_, user0_.someProperty as someProp4_0_, user0_1_.otherProperty as otherPro2_1_, user0_.userType as userType0_ from T_USER user0_ left outer join T_PowerUser user0_1_ on user0_.id=user0_1_.id 纗絛ㄒ mysql> select * from t_user;
+----+----------+-------------+--------------+ | id | userType | name | someProperty | +----+----------+-------------+--------------+ | 1 | Power | caterpillar | NULL | | 2 | Default | Bush | hu....hu... | +----+----------+-------------+--------------+ 2 rows in set (0.00 sec) mysql> select * from t_poweruser; +----+---------------+ | id | otherProperty | +----+---------------+ | 1 | Bla...Bla... | +----+---------------+ 1 row in set (0.00 sec) 硂睼ノ家Α拜肈琌膥┯約outer join穦Θ拜肈眤<join>fetch妮┦select ... <join table="T_PowerUser" fetch="select"> <key column="id" foreign-key="FK_USER"/> <property name="otherProperty" column="otherProperty"/> </join> ... 玥琩高ㄒㄓΩ琩高传ΘㄢΩselect琩高 Hibernate:
select user0_.id as id0_, user0_.name as name0_, user0_.someProperty as someProp4_0_, user0_.userType as userType0_ from T_USER user0_ Hibernate: select user_1_.otherProperty as otherPro2_1_ from T_PowerUser user_1_ where user_1_.id=? |