Dear Ralf, I have two questions to your solution.
1. Did you have already test your solution? 2. Can you write an example of mapping.xml for this solution? Looking forward to receive you answer, soon. Regards Andreas -----Urspr�ngliche Nachricht----- Von: Ralf Joachim [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 29. Mai 2003 12:43 An: [EMAIL PROTECTED] Betreff: Re: [castor-dev] Many-to-many: how to handle extra columns in an N:M table that REQUIRE data? Dear Bruce, if you have 2 classes with n:m mapping and no additional attributes for the mapping, this will be handled by castor as expected. The product - category examples shows how to do this. If additional attributes are required this should not be addressed by castor mapping but with the design of the application classes. Lets assume 2 classes foo and bar with both having id and name attributes. You need to create 2 tables and 2 classes to map them to database. foo (id , name) bar (id , name) If you do n:m mapping without additional attributes you can use the n:m mapping feature of castor that needs no additional class but an additional table. The table foobar for this mapping looks like: foobar ( foo_id , bar_id ) If you need additional attributes to be stored in foobar you have to create a class foobar and modify the table as follows: foobar (id , foo_id , bar_id , additional_attribute ) This design has a 1:n mapping between foo and foobar as well as a 1:n mapping between bar and foobar. The result is a n:m mapping between foo and bar with the possibility to store additional attributes in foobar. As it is easy to solve this by application design this should not be addressed in the refactoring. Regards Ralf ----- Original Message ----- From: "Bruce Snyder" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, May 28, 2003 9:58 PM Subject: Re: [castor-dev] Many-to-many: how to handle extra columns in an N:M table that REQUIRE data? > This one time, at band camp, Bart Jenkins said: > > BJ>Castor gods, > BJ> I have looked at the examples and have scoured the mail-list > BJ>archives and can't seem to find an answer to the following > BJ>Many-to-Many problem. I'll build on the N:M example that is > BJ>provided in the Castor examples: > BJ> > BJ>Categories and Products have an N:M relationship. That means that > BJ>there needs to be a 3rd table, in this case, "category_prod" that > BJ>holds the N:M relationship instances. Fine. But what if the > BJ>"category_prod" table has additional data columns (which they > BJ>typically do) and that are REQUIRED? > BJ> > BJ>>From the example file: \castor-0.9.4\examples\jdo\mapping.xml > BJ> > BJ>The perspective from the Categories side is: > BJ> > BJ><field name="categories" type="myapp.Category" required="true" > BJ>collection="vector" direct="false" lazy="false" transient="false"> > BJ> <sql name="category_id" many-table="category_prod" > BJ>many-key="prod_id" read-only="false" dirty="check" > BJ>transient="false" /> > BJ> <xml name="category" node="element" /> > BJ></field> > BJ> > BJ>The perspective from the Products side is: > BJ> > BJ><field name="products" type="myapp.Product" required="true" > BJ>collection="vector" direct="false" lazy="false" transient="false"> > BJ> <sql name="prod_id" many-table="category_prod" > BJ>many-key="category_id" read-only="false" dirty="check" > BJ>transient="false" /> > BJ> <xml name="product" node="element" /> > BJ></field> > BJ> > BJ>Ideally, I would think there should be a way to define the mapping > BJ>for the N:M table, "category_prod" and map that to a Java class > BJ>that can handle setting necessary fields as it is constructed. > BJ> > BJ>Currently, if my N:M table, "category_prod" has an extra column in > BJ>it that is REQUIRED, then a db.create(<product or category type > BJ>instance>) will fail with a > BJ> > BJ>java.sql.SQLException: ORA-01400: cannot insert NULL into > BJ>("USERNAME"."PRODUCT / CATEGORY"."CATEGORY_PROD") type error > BJ> > BJ>Will coding up a CREATE method get me around this problem? Is > BJ>there some additoinal mapping info I can give to have this done > BJ>automagically? > > Bart, > > This is not something that Castor can handle currently. However, this > is something that needs to be addressed in the refactoring. > > If Castor allowed an explicit many-to-many mapping to denote the > relationship between the two classes than this would be used or simply > employing the default mechanism when no explicit many-to-many mapping > is defined. > > Bruce > -- > perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");' > > ----------------------------------------------------------- > 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
