`

hibernate many to one

阅读更多

今天与到了一个令人可笑的事情,在以前的公司用struts 2+spring 3.2+hibernate.30在写pojo是用的Anotation,现在用hibernate以前的老版本,全部是手动的去配置,many-to-one  和one -to-many.现在总结一下!

例子:有一个order表 有一个container表。两个关系是one-to-many的关系!

1:   我们要在container(子表)中,配置一个order(父表)的entity.如果说在物理表中。container引用的外间是order_foreign字段。则:<many-to-one  column="orderForeign" ref="order_foreign" table="order"/>

2:问题来了,如果要在拿到子表的时间同时也lazy=true到子表container的信息。

  <set column="我们的set" lazy="true">

  <column />//忘记了,应该是..key的东西,反正就是我们子表container的“order_foreign”

  <ref column="container"/>

</set>

一定要记住!

工作就是要不段的去总结,这样我们才能有所收获!希望有人看到,多多留言,提提意见,互相进步。

 

 

 

 

1
0
分享到:
评论
2 楼 isaiahzhong 2012-12-07  
         我也没看懂你说的意思?
1 楼 niuyanan 2010-05-28  
没看明白你所说的问题,不过你说多总结还是很好的!

相关推荐

Global site tag (gtag.js) - Google Analytics