-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HELP:HQL syntax for quering across many-to-many relationship
PostPosted: Tue May 20, 2008 3:20 pm 
Newbie

Joined: Mon May 12, 2008 8:42 pm
Posts: 2
We are trying to formulate a HQL to cross a many-to-many relationship with a criteria against the remote class

i.e. we want to find all 'users' who are in a certain 'group'

UserBean and GroupBean are related via GroupUserBean class. The GroupUserBean class has two one-to-many relationships

The relationship work fine, I am just having difficulty in coming up with the correct syntanx in the HQL to describe what I want????

I want 'from UserBean where groupUserAssocBeans.groupId in (select id from GroupBean where name in ('YourGroup', 'ourGroup')'

Would that work??
Hibernate version: 3.5 2

Mapping documents:
Code:
    <class name="com.UserBean" table="USERS">
        <id name="name" type="string" column="USER_NAME"/>
        <set name="groupUserAssocBeans" inverse="true" cascade="save-update">
            <key column="USER_NAME"/>
            <one-to-many class="com.GroupUserAssocBean"/>
        </set>
    </class>

    <class name="com.GroupUserAssocBean"
           table="GROUP_USER_ASSOC">

        <composite-id name="id" class="com.GroupUserAssocBean$Id">
            <key-property name="groupId" access="field" column="GROUP_ID"/>
            <key-property name="user" access="field" column="USER_NAME"/>
        </composite-id>

        <property name="persistanceDate" type="date" column="PERSISTENCE_DATE"/>
        <property name="userAliasId" type="string" column="USER_ALIAS_ID"/>

        <many-to-one name="groupBean"
                     column="GROUP_ID"
                     cascade="save-update"
                     not-null="true"
                     insert="false"
                     update="false"/>

        <many-to-one name="userBean"
                     column="USER_NAME"
                     cascade="save-update"
                     not-null="true"
                     insert="false"
                     update="false"/>

    </class>

    <class name="com.GroupBean" table="GROUP">
        <id name="id" type="integer" column="GROUP_ID">
            <generator class="sequence">
                <param name="sequence">GROUP_ID_SEQ</param>
            </generator>
        </id>
        <property name="description" type="string" column="DESCRIPTION"/>
        <property name="creatorUserId" type="string" column="CREATOR_USER_ALIAS_ID"/>
        <property name="createdDate" type="date" column="CREATE_DATE"/>

        <set name="groupUserAssocBeans" inverse="true" cascade="all-delete-orphan">
            <key column="GROUP_ID" />
            <one-to-many class="com.GroupUserAssocBean"/>
        </set>
    </class>


Name and version of the database you are using: Oracle 10GR2


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 29, 2008 8:10 am 
Newbie

Joined: Tue Jul 29, 2008 8:08 am
Posts: 3
Location: Atlanta
Did you ever get a response to this question or did you figure it out on your own?

I'd really appreciate your HQL for this query to point me in the right direction.

Thanks - Jackson


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.