Hibernate使用——一对一关联示例
?
TOham.java
?
?
?
执行代码:
?TOham.java:?
?
执行代码:
?其中property-ref指定为TOham的属性名为can,意思是TOham的can就是关联着本类TCancan的。这样就实现了映射层面的双向关联。
在执行代码:
Hibernate: select tcancan0_.id as id2_2_, tcancan0_.name as name2_2_, tcancan0_.think as think2_2_, toham1_.id as id0_0_, toham1_.name as name0_0_, toham1_.meditation as meditation0_0_, toham1_.group_id as group4_0_0_, toham1_.friend_id as friend5_0_0_, tlulu2_.id as id1_1_, tlulu2_.name as name1_1_, tlulu2_.sixthsense as sixthsense1_1_ from t_cancan tcancan0_ left outer join t_oham toham1_ on tcancan0_.id=toham1_.friend_id left outer join t_lulu tlulu2_ on toham1_.id=tlulu2_.id where tcancan0_.id=??
此处就引申了一个问题,若一个实体的映射关联多了,就不能总让其join来join去了,那么就要考虑如何设置映射配置,使得性能最优化。。。
?
?