我遇到问题hql
我有3张桌子
1.用户(user_id = pk,用户名)
2. groups(group_id = pk,group_name)
3. usergroups(user_id = fk,group_id = fk)
<hibernate-mapping>
<class name="com.model.authRole.UserGroups" table="user_groups" catalog="db_realm" optimistic-lock="version">
<composite-id name="id" class="com.model.authRole.UserGroupsId">
<key-property name="userId" type="int">
<column name="user_id" />
</key-property>
<key-property name="groupId" type="int">
<column name="group_id" />
</key-property>
</composite-id>
<many-to-one name="groups" class="com.model.authRole.Groups" update="false" insert="false" fetch="select">
<column name="group_id" not-null="true" />
</many-to-one>
<many-to-one name="users" class="com.model.authRole.Users" update="false" insert="false" fetch="select">
<column name="user_id" not-null="true" />
</many-to-one>
<property name="aktiv" type="boolean">
<column name="aktiv" not-null="true" />
</property>
</class>
我想显示用户名和group_name
,但是hql
from UserGroups ug
inner join Users u on u.user = ug.user_id
inner join Groups g on g.group = ug.group_id
并记录错误
org.hibernate.hql.internal.ast.QuerySyntaxException:预期的路径 加入! [来自com.model.authRole.UserGroups ug内部联接 用户u on u.user = ug.user_id inner join g g.group = ug.group_id]
如何解决?
答案 0 :(得分:0)
我假设类UserGroups
包含来自User
的对象和来自Group
类的对象
session.createQuery("from UserGroups ug where ug.User = :user and ug.Group =:group").setParameter("user", (Users)session.get(Users.class,user_id)).setParameter("group", (Groups)session.get(Groups.class,group_id));