-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-many and the link table woes
PostPosted: Thu Sep 11, 2003 5:24 am 
Newbie

Joined: Thu Sep 11, 2003 4:39 am
Posts: 3
Location: Zagreb, Croatia
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 7:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
did you flush() the session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 7:10 am 
Newbie

Joined: Thu Sep 11, 2003 4:39 am
Posts: 3
Location: Zagreb, Croatia
Shiver me timbers, Gavin! I did not flush the session!

After adding the call to session's flush method, everything works as expected!

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.