Hello Patrick, I think I have a very similar problem as Mark has (1-to-many in my case) and I tried to solve it the way you described. However, the A.addB(B b)-method never gets called when I unmarshal from a XML file. Nevertheless, all a-objects contain their bs properly it's just the bs not referencing back. Any ideas? Thanks in advance, Achim
-----Original Message----- From: Patrick van Kann [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 11, 2002 12:55 PM To: [EMAIL PROTECTED] Subject: Re: [castor-dev] Many-to-many relationship not persisting Hello Mark, I have also noticed that you don't map the relationship bi-directionally. Castor requires your A class to have a collection of Bs and your B class to have a collection of As. You must explicitly add the As to the Bs and vice-verse (this can be done in the addXXXXX() method within the persistent class to save you remembering in the client code). i.e. in class A addB(B b) { b.addA(this); this.bs.put(b); //or whatever, I am shooting from the hip here ;-) } You therefore also need to address this in the mapping. <class name="b" identity="id"> <map-to table="b_table" /> <field name="id" /> <field name="as" type="a" collection="map"> <sql name="aId" many-table="bridge_table" many-key="bId" /> </field> </class> I hope this helps. Patrick Mark Woon wrote: > Hmm... > > After playing with this some more, it looks like I need to get my B > objects within the current transaction for this to work. Is there any > way around this? > > > Thanks, > -Mark > > > Mark Woon wrote: > >> Hi all... >> >> I've encountered an interesting problem where Castor is under the >> impression that my many-to-many relationships are not persistable. >> I've an object A which has a collection of object B's. The db schema >> is something like: >> >> A table >> ------- >> id >> >> >> B table >> ------- >> id >> >> Bridge table >> ------------ >> aId >> bId >> >> <class name="a" type="a" identity="id"> >> <map-to table="a_table" /> >> <field name="id" /> >> <field name="b" type="b" collection="map"> >> <sql name="bId" many-table="bridge_table" many-key="aId" /> >> </field> >> </class> >> >> <class name="b" identity="id"> >> <map-to table="b_table" /> >> <field name="id" /> >> </class> >> >> >> I've created a new A object, and added a few B objects into A's >> collection of B objects. When I try calling db.create(a), the >> appropriate entry in a_table gets created, but nothing gets created >> in the bridge_table. I can trace it all the way to >> ClassMolder.create(), where it checks to see if many-to-may >> relationships are persistable (by calling tx.isPersistent(oo)) and is >> told that they're NOT persistable. B implements TimeStampable, but >> I'm guessing that's not enough. Does anyone have any ideas as to why >> this may be the case? I just don't understand what Castor is doing >> at this point. > > > ----------------------------------------------------------- If you > wish to unsubscribe from this mailing, send mail to > [EMAIL PROTECTED] with a subject of: > unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev ----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to [EMAIL PROTECTED] with a subject of: unsubscribe castor-dev
