`
pub10
  • 浏览: 2782 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

hibernate ont-to-many 的问题 get不到值

阅读更多
在one-to-many中,数据库里面有对应数据,为什么parent.getChilds() get不到值

Parent.hbm.xml
<set name="chhilds" inverse="true" lazy="true" cascade="all">
	<key column="chi_id"/>
	<one-to-many class="Child"/>
</set>

Childs.hbm.xml
<many-to-one name="parent" column="par_id"
	class="Parent" not-null="false" cascade="all">
</many-to-one>


是以前的一个SSH框架,采用openSessionInViewFillter,用的是hibernate2,spring的版本也相对较老.

请问为什么parent.getChilds() get不到值,是不是hibernate 和 spring 的版本原因,还是新的版本也会有这样的问题?
测试many-to-many没有问题
分享到:
评论
3 楼 mcikevin 2007-01-20  
<set name="chhilds" ....>
其中name应该为"childs"
2 楼 pub10 2007-01-17  
[quote="mcikevin]配置文件有问题,应该是这样的:
Parent.hbm.xml  
<set name="chhilds" inverse="true" lazy="true" cascade="all"> 
    <key column="par_id"/> 
    <one-to-many class="Child"/> 
</set> 
 
Childs.hbm.xml  
<many-to-one name="parent" column="par_id" 
    class="Parent" not-null="false" cascade="all"> 
</many-to-one> 

哦,对不起,刚刚是我写错了.写得急.实际还是get不到.
1 楼 mcikevin 2007-01-17  
pub10 写道
在one-to-many中,数据库里面有对应数据,为什么parent.getChilds() get不到值

Parent.hbm.xml
<set name="chhilds" inverse="true" lazy="true" cascade="all">
	<key column="chi_id"/>
	<one-to-many class="Child"/>
</set>

Childs.hbm.xml
<many-to-one name="parent" column="par_id"
	class="Parent" not-null="false" cascade="all">
</many-to-one>


是以前的一个SSH框架,采用openSessionInViewFillter,用的是hibernate2,spring的版本也相对较老.

请问为什么parent.getChilds() get不到值,是不是hibernate 和 spring 的版本原因,还是新的版本也会有这样的问题?
测试many-to-many没有问题
配置文件有问题,应该是这样的:
Parent.hbm.xml  
<set name="chhilds" inverse="true" lazy="true" cascade="all"> 
    <key column="par_id"/> 
    <one-to-many class="Child"/> 
</set> 
 
Childs.hbm.xml  
<many-to-one name="parent" column="par_id" 
    class="Parent" not-null="false" cascade="all"> 
</many-to-one> 

相关推荐

Global site tag (gtag.js) - Google Analytics