关于网友提出的“ hibernate中one-to-many问题,在线等晚上7点结贴)”问题疑问,本网通过在网上对“ hibernate中one-to-many问题,在线等晚上7点结贴)”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: hibernate中one-to-many问题,在线等晚上7点结贴)
描述: 表UserCommon :
public class UserCommon {
private String id;
private String userID;
private String objectID;
private Integer sequence;
//存放Account对象的列表
private List accounts=new ArrayList();
}
表Account:
public class Account {
private String id;
private String accountCode;
private String accountTypeID;
}
问题:UserCommon.objectID与Account.id关联(one-to-many),应该怎样写相应的UserCommon.hbm.xml和Account.hbm.xml文件?
解决方案1: 楼上的说反拉
UserCommon.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
Account.hbm.xml
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
xxx为你的包的路径
解决方案2: 这样看你的Account是主表,就是one的这边。
UserCommon是子表,many的这边。
在Account类中增加:
private Set ucs;//放置UserCommon实体集
在UserCommon类中增加:
private Account account;//指向主表
在Account.hbm.xml中:
在UserCommon.hbm.xml中:
这些配置中对应的配置可以参看hibernate中文文档,根据你的实际应用需要来配。
以上介绍了“ hibernate中one-to-many问题,在线等晚上7点结贴)”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3582296.html