Joined: Fri Mar 19, 2004 3:53 pm Posts: 6
|
Hibernate version:
2.1.6
Mapping documents:
The location side:
<map
name="groups"
table="location_group"
lazy="false"
sort="natural"
inverse="false"
cascade="save-update"
>
<key
column = "location_id"
>
</key>
<index
column="group_id"
type="long"
/>
<many-to-many
class="com.example.model.Group"
column="group_id"
outer-join="auto"
/>
</map>
The Group side:
<map
name="locations"
table="location_group"
lazy="false"
sort="unsorted"
inverse="true"
cascade="save-update"
>
<key column="group_id"></key>
<index column="location_id" type="long"/>
<many-to-many
class="com.example.model.Location"
column="location_id"
outer-join="auto"
/>
</map>
Background Information:
Many locations can have many groups.
The primary key of the app_location table is "location_id" and the primary key of the app_group table is "group_id".
What I want to do:
I want to set up a many-to-many relationship between the two classes Location and Group. Location has a Map named "groups". Group has a Map named "locations".
When I retrieve a location object by its "location_id" I want all of the "groups" to be loaded into the "groups" Map and have the group objects stored in the HashMap by their unique "group_id". Thus, allowing me to remove an individual group from the groups Map by calling on groups.remove(group.getGroupId()); and then calling on the Hibernate save method.
Hopefully this makes sense. I am a newbie... so I think that my example mapping is probably full of errors. I have been using the Hibernate in Action book to map this out... but have not been able to determine what I need to do for a mapping of type Map. I think I need to specify an "element" in this mapping.
Thanks in advance!
Christopher
|
|