I'm trying to implement a simple many-to-many relationship. My test application has two objects: a Service, and a Location. Obviousely, some random Service can be performed at no, one or an arbitrary number of locations.
Now, I want to have a set in the Service class that represents all of the Locations where this Service can be performed.
Here's the relevant part of the Service class mapping:
Code:
<set name='locations' role='locations' table='location_service' cascade='all'>
<key column='service_id'/>
<many-to-many column='location_id' class='com.tramot.ec.engine.data.Location'/>
</set>
So, the many-to-many link data should be stored in the
location_service table. Or so I thought...
I create a Service, a Location, put the Location into a set, pass it to Service. I do a
session.saveOrUpdate and both the Service and all of it's locations are saved. But... there's nothing in the link table.
Which, when loading stuff causes none of the Locations to appear in my set in the Service object; logically since there are no Service<->Location mappings in the link table.
I've trawled through both the FAQ, the Hibernate reference, and several online tutorials. I'm not sure if I'm missing something here, or is it my own job to insert the stuff into the link table? Could somebody please shed some light on this issue?
Thanks for your time!
Sincerely yours,
Ivan Stojic