Hi, Hard to say exactly what you should do or not do.
You have the possibility to define the "right" side by using inverse keyword in sculptor dsl, but that is maybe nothing new to you. If you always update from UserGroup to User then you should place inverse in User (I think). The add and remove methods generated by Sculptor, e.g. UserGroup.addUser, should be used with care since they update both sides of the associations. You might need to add only on one side (the "right", non inverse side). You do that by operating directly on the collections, userGroup.getUsers().add(user). In the end bidirectional associations are evil. Should be avoided if possible. Ask yourself if you really need to have them bidirectional. Is it necessary to traverse from UserGroup to all users of the group? Pretty many if you are developing Facebook or Linkedin ;-) Is it possible to replace the association (at least one direction of it) with a query (repository operation)? /Patrik Sascha Broich wrote: > > Hi, > > I have a little problem. > > There are two classes, User and UserGroup, who are connected bidirectional > many-to-many. > Now when I edit a userGroup and add users to it these changes are not > saved because hibernate handles such connections only on one side. One > problem is, that I have to know the "right" side of the connection when I > save the changes. This is nasty but manageable. The other problem occurs > when I try to save these changes the way hibernate wants. > The scenario is: I edit the userGroup, add or remove some users and save. > First I tried to save the userGroup and then the changed users. Then I > tried it the other way. But I run always in an OptimisticLockException. > Now I'm confused. How do I handle such cases? > > > Regards, > Sascha Broich > > -- > Sascha Broich > Development > > TSA - Teleport Sachsen-Anhalt Service GmbH > Herrenstraße 20 - D-06108 Halle > > Tel: +49 39203 8 2524 - Fax: +49 39203 8 2511 > E-Mail: sascha.bro...@tsa.de > > Firmensitz: Steinfeldstraße 5, D-39179 Barleben > Niederlassung: Herrenstraße 20, D-06108 Halle > Geschäftsführer: Marco Langhof, Thomas Patzelt > Prokurist: Heiko Bosse > Amtsgericht: Stendal HRB 6388 > http://www.tsa.de > > > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > Fornax-developer mailing list > Fornax-developer@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/fornax-developer > > -- View this message in context: http://old.nabble.com/Bidirectional-Many-To-Many-Connection-and-Save-tp27605064s17564p27614384.html Sent from the Fornax-Platform mailing list archive at Nabble.com. ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ Fornax-developer mailing list Fornax-developer@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fornax-developer