-->
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: Many-to-many: find all groups that a user is participating
PostPosted: Wed Nov 08, 2006 3:17 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hi,

I have got a mapping for a User, a Group and a UserGroup. So a user can participate in more than one group and a group can have more than one user. Each domain model object has a Set of the other (a User has a Set of subscribed groups and vice versa).
Now I'm searching for a command to get all the groups a user is participating in. I tried something like this:

Code:
getHibernateTemplate().find("from Group as g where ......");


It's incomplete. I would appreciate some help to find the complete command and even better a use of the Criteria-interface(s) Hibernate delivers.

Thanks.

Hibernate version: 3

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="de.tfhberlin.eclipsophone.server.beans" auto-import="true">
<class name="Group" table="Groups">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native" />
</id>
<property name="name" column="name" type="string" />
<property name="description" column="description" type="string" />
<set name="participating_users" table="UserGroups">
<key column="group_id" />
<many-to-many column="user_id" class="User" />
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="de.tfhberlin.eclipsophone.server.beans" auto-import="true">
<class name="User" table="Users">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name" column="name" type="string"/>
<property name="password" column="password" type="string"/>
<set name="subscribed_groups" table="UserGroups" inverse="true">
<key column="user_id"/>
<many-to-many class="Group" column="group_id"/>
</set>
</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="de.tfhberlin.eclipsophone.server.beans" auto-import="true">
<class name="UserGroup" table="UserGroups">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<property name="user_id" column="user_id" type="long"/>
<property name="group_id" column="group_id" type="long"/>
</class>
</hibernate-mapping>

Name and version of the database you are using: MySQL 5


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 7:32 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
No ideas, hints, ... ?


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.