问题描述
publicclassCapes{/***文件夹ID*/privateintid;/***所属用户*/privateUseruser;/***文件夹名称*/privateStringname;/***创建日期*/privateDatecreateTime;/***子文件夹*/privateSet<Capes>subCapes;/***用户资源*/privateSet<Source>subSources;}表结构CREATETABLE`capes`(`ID`int(11)NOTNULLauto_incrementCOMMENT'?審?ID',`USER_ID`int(11)defaultNULLCOMMENT'強???ID',`NAME`varchar(20)NOTNULLCOMMENT'?審?柤?',`CREATE_TIME`dateNOTNULLCOMMENT'?寶??',`PARENT_CAPES_ID`int(11)defaultNULLCOMMENT'晝?審?ID',PRIMARYKEY(`ID`))ENGINE=InnoDBAUTO_INCREMENT=16DEFAULTCHARSET=utf8;现在我想通过PARENT_CAPES_ID`查找capes下的子capes应该怎么写啊?
解决方案
解决方案二:
在capes表的hibernate映射中加下面代码<setname="subCapes"lazy="false"><keycolumn="id"/><one-to-manyclass="Capes"/></set>
解决方案三:
该回复于2011-03-14 17:08:44被版主删除
解决方案四:
@EntitypublicclassCapes{privateintid;privateStringname;privateDatecreateTime;privateSet<Capes>subCapes=newHashSet<Capes>();privateCapesparentCapes;@Id@GeneratedValuepublicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicDategetCreateTime(){returncreateTime;}publicvoidsetCreateTime(DatecreateTime){this.createTime=createTime;}@OneToMany(cascade={CascadeType.ALL},mappedBy="parentCapes")publicSet<Capes>getSubCapes(){returnsubCapes;}publicvoidsetSubCapes(Set<Capes>subCapes){this.subCapes=subCapes;}@ManyToOne@JoinColumn(name="PARENT_CAPES_ID")publicCapesgetParentCapes(){returnparentCapes;}publicvoidsetParentCapes(CapesparentCapes){this.parentCapes=parentCapes;}}
解决方案五:
引用1楼bbsfly1239的回复:
在capes表的hibernate映射中加下面代码<setname="subCapes"lazy="false"><keycolumn="id"/><one-to-manyclass="Capes"/></set>
上面的添加过了用spring怎么写啊?我用myeclipse生成的DAO里面写的是capesService.findByParentId()可是根本不对啊
解决方案六:
引用3楼evil_cloud的回复:
Javacode@EntitypublicclassCapes{privateintid;privateStringname;privateDatecreateTime;privateSet<Capes>subCapes=newHashSet<Capes>();privateCapesparent……
大哥您这是何意啊?小弟不懂啊
解决方案七:
引用4楼khtnly的回复:
引用1楼bbsfly1239的回复:在capes表的hibernate映射中加下面代码<setname="subCapes"lazy="false"><keycolumn="id"/><one-to-manyclass="Capes"/></set>上面的添加过了用spring怎么写啊?我用myeclipse生成的DAO里面写的是……
这个在配置文件里写的,或者用标签的方式告诉hibernate,设置他们的级联然后取的时候带子对象...
解决方案八:
fromcapesm,capesnwhere..