问题描述
hibernate问题: 如果有两张表分别是userinfo和groupinfo userinfo(userId,userName,deptId) groupinfo(groupId,groupName) ,userinfo里面deptId和groupinfo的groupId是主外键关系。 那么user.hbm.xml和groupinfo.hbm.xml应该怎么配置。我只要取userinfo就可以取到groupName的值.以下是我的配置,现在可以运行正常 但就是取不到groupName的值。请问应该怎么配置??? userinfo============================================================<hibernate-mapping package="org.materialManager.model"> <class name="UserInfo" table="UserInfo" schema="dbo" catalog="Material"> <id name="userId" type="integer"> <column name="userId"> <generator class="increment"> </id> <many-to-one name="groupinfo" class="GroupInfo" outer-join="true" fetch="select"> <column name="deptId"> </many-to-one> <property name="userName" type="string"> <column name="userName" length="50" not-null="true"> </property> </class> Groupinfo=============================<hibernate-mapping package="org.materialManager.model"> <class name="GroupInfo" table="GroupInfo" schema="dbo" catalog="Material"> <id name="groupId" type="integer"> <column name="groupId"> <generator class="increment"> </id> <property name="groupName" type="string"> <column name="groupName" length="50" not-null="true"> </property> <set name="userInfos"> <key> <column name="deptId"> </key> <one-to-many class="UserInfo"> </set> </class></hibernate-mapping>
解决方案
<many-to-one name="groupinfo" class="GroupInfo" outer-join="true" fetch="select" lazy="false"> <column name="deptId" /></many-to-one>然后userinfo.getGroupinfo().getGroupname()