说明.程序是SSH框架结构...
1.首先,我的有一个“用户表(User)”。一个“分组表(Group)”,一个“用户所在分组表(UserGroup)”。一个“分组拥有权限表(GroupPriv)”。
2.“用户所在分组表”和“分组拥有权限表”都没有主键。
3.使用hibernate映射过来的时候,由于“用户所在分组表”和“分组拥有权限表”没有主键ID.自动生成了一个联合主键类UserGroupId.class和GroupPrivId.class 他们里面就是对应表的所有字段.
并且配置文件如下.(UserGroup.hbm.xml)
<hibernate-mapping>
<class name="com.yss.projectmgr.entity.UserGroup" table="pms_usergroup" catalog="ysspmsdb">
<composite-id name="id" class="com.yss.projectmgr.entity.UserGroupId">
<key-property name="account" type="java.lang.String">
<column name="account" length="30" />
</key-property>
<key-property name="group" type="java.lang.Integer">
<column name="group" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>当我要查询 用户名(account)为 "a" 的都在什么分组里面时
String hql = "from userGroup as ug where ug.id.account = "+ account ;
return this.getHibernateTemplate().find(hql);抛出异常
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException:
usersGroup is not mapped [from usersGroup as ug where ug.id.account = admin];
nested exception is org.hibernate.hql.ast.QuerySyntaxException:
usersGroup is not mapped [from usersGroup as ug where ug.id.account = admin] 这种联合主键如何查询对应的实体数据啊...\
请教高手!!! 在线等!
1.首先,我的有一个“用户表(User)”。一个“分组表(Group)”,一个“用户所在分组表(UserGroup)”。一个“分组拥有权限表(GroupPriv)”。
2.“用户所在分组表”和“分组拥有权限表”都没有主键。
3.使用hibernate映射过来的时候,由于“用户所在分组表”和“分组拥有权限表”没有主键ID.自动生成了一个联合主键类UserGroupId.class和GroupPrivId.class 他们里面就是对应表的所有字段.
并且配置文件如下.(UserGroup.hbm.xml)
<hibernate-mapping>
<class name="com.yss.projectmgr.entity.UserGroup" table="pms_usergroup" catalog="ysspmsdb">
<composite-id name="id" class="com.yss.projectmgr.entity.UserGroupId">
<key-property name="account" type="java.lang.String">
<column name="account" length="30" />
</key-property>
<key-property name="group" type="java.lang.Integer">
<column name="group" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>当我要查询 用户名(account)为 "a" 的都在什么分组里面时
String hql = "from userGroup as ug where ug.id.account = "+ account ;
return this.getHibernateTemplate().find(hql);抛出异常
Exception in thread "main" org.springframework.orm.hibernate3.HibernateQueryException:
usersGroup is not mapped [from usersGroup as ug where ug.id.account = admin];
nested exception is org.hibernate.hql.ast.QuerySyntaxException:
usersGroup is not mapped [from usersGroup as ug where ug.id.account = admin] 这种联合主键如何查询对应的实体数据啊...\
请教高手!!! 在线等!
@JoinColumn(name = "联合主键")