-->
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.  [ 1 post ] 
Author Message
 Post subject: Persisting many-to-many
PostPosted: Wed Jul 23, 2008 7:30 am 
Newbie

Joined: Mon Jul 14, 2008 7:08 am
Posts: 18
Suppose I have objects of type A and objects of type B. Many-to-many relationship is set. Domain model don't allow creation of new instances of type A and type B. The only way I can modify domain model:
1) For particular instance of type A add or remove references to instances of type B
2) For particular instance of type B add or remove references to instances of type A
That is there are no new instances at all. Only association table in many-to-many relationship is changing. Presentation layer and domain model are separated, so retrieved objects are always detached. Mapping files are written.

1) How can I work with such model on client side? For example:
ICollection<A> cA contains Ainstances;
ICollection<B> cB contains Binstances;
Ainstance.Remove(Binstance) - this won't work, because Ainstance.CollectionOfB does not contain object equal to Binstance. I have to find it by id, save reference to it and then remove.
I don't think that this is the right way.
2) How can I persist such model? NHibernate always throws exceptions that "a different object with the same identifier value was already associated with the session" when I write this: foreach (var Ainstance in cA) Session.SaveOrUpdate(Ainstance);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.