0

下面是将获取结果的 sql 查询,该结果是许多内部连接的组合。相应的 pojo 是

 Table             JAVA POJO
    rtyuUSER          User
    rtyu_GROUP         rtyu

user.java 包含以下属性

更新由更新比更新日期

rtyu_GROUP.java 包含以下属性

ID;

code;

姓名;

获取记录的查询.. SELECT distinct u.name, u.updated_by, u.updateddate FROM rtyuUSER u, rtyuuser_rtyu ug, rtyurtyu gwhere u.id = ug.user_id and ug.rtyu_id = g.id and u.ACTIVE_FLAG= 'Y' 和 g.id 不在 (10,11) 中按 u.name 排序

并且表之间的关系在 hbm 中定​​义为 ,

<class name="User" table="rtyu_USER" dynamic-update="true" select-before-update="true">
<property name="name" type="string" />
<property name="updated" type="timestamp" column="UPDATEDDATE"  />
        <property name="updatedBy" column="UPDATED_BY" type="string"/>
        <property name="active" type="yes_no" column="FLAG" />
        <set name="groups" table="rtyu_USER_GROUP" lazy="true" inverse="false" sort="natural">
            <key column="USER_ID" />
            <many-to-many column="GROUP_ID" class="Group" />
        </set>


        and the nother class tag is defined as..

        <class name="Group" table="rtyu_GROUP" mutable="false">
        <id name="id" unsaved-value="0" type="long" access="property" />
        <property name="code" type="string" />
        <property name="name" type="string" />
        <set name="permissions" table="rtyu_GROUP_PERMISSION" inverse="true" lazy="false" sort="natural">
            <key column="GROUP_ID" />
            <many-to-many column="PERMISSION_ID" class="Permission" />
        </set>
    </class>



Now could you please advise how to write HQL for this for this..folks please advise for this
4

1 回答 1

0

如果我理解正确,它将是这样的:

SELECT DISTINCT FROM
User u
INNER JOIN u.groups as g
WHERE u.active='Y' AND g.id NOT IN (10,11)
ORDER BY u.name
于 2013-08-03T06:10:16.590 回答