这样看你的Account是主表,就是one的这边。
UserCommon是子表,many的这边。
在Account类中增加:
private Set ucs;//放置UserCommon实体集在UserCommon类中增加:
private Account account;//指向主表在Account.hbm.xml中:
<set name="ucs" cascade="none" table="UserCommon所对应的数据表的表名">
<key column="UserCommon所对应的数据表中指向Account的id的列名" />
<one-to-many class="UserCommon" />
</set>
在UserCommon.hbm.xml中:
<many-to-one name="account" class="Account" column="UserCommon所对应的数据表中指向Account的id的列名" cascade="none"/>
这些配置中对应的配置可以参看hibernate中文文档,根据你的实际应用需要来配。
UserCommon是子表,many的这边。
在Account类中增加:
private Set ucs;//放置UserCommon实体集在UserCommon类中增加:
private Account account;//指向主表在Account.hbm.xml中:
<set name="ucs" cascade="none" table="UserCommon所对应的数据表的表名">
<key column="UserCommon所对应的数据表中指向Account的id的列名" />
<one-to-many class="UserCommon" />
</set>
在UserCommon.hbm.xml中:
<many-to-one name="account" class="Account" column="UserCommon所对应的数据表中指向Account的id的列名" cascade="none"/>
这些配置中对应的配置可以参看hibernate中文文档,根据你的实际应用需要来配。
解决方案 »
- 用jdbcTemplate插入数据到数据库中,事务提交却无法保存数据
- ERROR JDBCExceptionReporter:78 - 将截断字符串或二进制数据。
- ScheduledThreadPoolExecutor定时问题,求高手!在线等!!!!!!
- oracle10g负载均衡与集群,如何做?
- 继续发帖求助:广州宇信易诚 情况和待遇怎样?!
- 求JavaMail源代码文件
- 可以往JavaScript的数组中放置JavaBean对象吗
- java.socketException
- 使用jsf时的错误:Error testing property 'name' in bean of type null。请大家帮帮忙
- 用Eclipse开发Hibernate时,运行不出来问题
- 學過.net,c++想轉到java,不過概念太多,我該怎麼理解這些概念呢?比如tomcat?
- jdbc 关于db2数据库的问题。。。现在连接没错误,但是没反应。。
UserCommon.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="xxx.UserCommon" table="UserCommon">
<id name="objectID" column="objectID" type="integer">
<generator class="native"/>
</id>
<property id="id" column="id" type="string"/>
<property id="userID" column="userID" type="string"/>
<property id="sequence" column="sequence" type="integer"/>
<bag name="Account" cascade="all" order-by="id">
<key column="objectID"/>
<one-to-many class="xxx.Account"/>
</bag>
</class>
</hibernate-mapping>Account.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="xxx.Account" table="Account">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>
<property name="accountCode" column="accountCode" type="string"/>
<property name="accountTypeID" column="accountTypeID" type="string"/>
<many-to-one name="UserCommon" column="objectID" class="xxx.UserCommon"/>
</class>
</hibernate-mapping>xxx为你的包的路径
恕我学识浅薄,不过我确实还没见过你这样的配置.
还有,楼主的UserCommon表通过一个外键objectID与Account表的主键id关联,UserCommon很明显的就是子表,Account是主表,你怎么说是反了?
private String id;
private String userID;
private String objectID;
private Integer sequence;
//存放Account对象的列表
private List accounts=new ArrayList();//该类不是有个Account的集合吗
}
我没认真看啊,我还以为objectID是主键啊 :(
这两个表如果用SQL语句连接起来,如下:
Select UserCommon.id,
Account.id AS AccountID, Res_Account.AccountCode
FROM Res_User_Common
INNER JOIN Account ON _Account.id=UserCommon.objectID
WHERE UserCommon.UserID='5663d688-9110-4e9b-a3f8-fa3ef22f0e45'也就是:
我从UserCommon中选出一个数据对象usercommon后,usercommon中就要有一个相应的Account对象account,像你那样配置能实现嘛?