Bruce, Are you suggesting that I NOT use an N:M mapping and treat the 3 tables involved (Category, Product, Category_Prod) separately?
Bart -----Original Message----- From: Bruce Snyder [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 28, 2003 3:58 PM To: [EMAIL PROTECTED] 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 archives and BJ>can't seem to find an answer to the following Many-to-Many problem. I'll BJ>build on the N:M example that is provided in the Castor examples: BJ> BJ>Categories and Products have an N:M relationship. That means that there BJ>needs to be a 3rd table, in this case, "category_prod" that holds the N:M BJ>relationship instances. Fine. But what if the "category_prod" table has BJ>additional data columns (which they 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" many-key="prod_id" BJ>read-only="false" dirty="check" 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" many-key="category_id" BJ>read-only="false" dirty="check" 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 for the BJ>N:M table, "category_prod" and map that to a Java class that can handle BJ>setting necessary fields as it is constructed. BJ> BJ>Currently, if my N:M table, "category_prod" has an extra column in it that BJ>is REQUIRED, then a db.create(<product or category type instance>) will fail BJ>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 there some BJ>additoinal mapping info I can give to have this done 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
