Joined: Tue Sep 28, 2004 2:03 pm Posts: 9 Location: Fullerton, CA
|
I have a many-to-many relationship set up where a User can have many Roles and many Users can have the same Role. Do I need to make the relationship bidirectional to query Users by Role?
For example, given a Role's id, I'd like to get a list of the Users that have that Role. My application is already written, so I'd prefer not to have to go back and make the relationship bidirectional just for this query.
Thanks,
Brian
Hibernate version:
2.1.6
Mapping documents:
User.hbm.xml:
<hibernate-mapping>
<class name="com.briankuhn.vocab.data.value.User" table="users">
<id name="id" column="id" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="name" column="name" not-null="true"/>
<property name="password" column="password" not-null="true"/>
<set name="roles" table="user_roles" cascade="save-update">
<key column="user_id"/>
<many-to-many class="com.briankuhn.vocab.data.value.Role" column="role_id"/>
</set>
</class>
</hibernate-mapping>
Role.hbm.xml
<hibernate-mapping>
<class name="com.briankuhn.vocab.data.value.Role" table="roles">
<id name="id" column="id" unsaved-value="0">
<generator class="increment"/>
</id>
<property name="name" column="name" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
no code yet
Full stack trace of any exception that occurs:
no exceptions yet
Name and version of the database you are using:
hsqldb vX.X
The generated SQL (show_sql=true):
no sql yet
Debug level Hibernate log excerpt:
no logs yet
|
|