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