Hi Bikram,

Bikram B Kapoor wrote:

But in a different scenario, where the table structure changes to

table: mycategory
ID - primary key
name varchar

table: myproducts -- the foriegn key of category table is not present
pid - primary key
prodname

table: mycategoryproduct
cpid primary key
ID -- foriegn key of mycategory table
pid -- foriegn key of myproducts table

In this case what all changes are required in the repository.xml file and the classes and if somebody can give me some URL's or articles regarding
Vector and collection usage in OJB i.e. where to use Vector and where
to use collection.



Sounds like a non-decomposed m:n relation with indirection table 'mycategoryproduct'.
http://db.apache.org/ojb/docu/guides/basic-technique.html#Support+for+Non-Decomposed+m%3An+Mappings


Both classes need a Collection or List (depend on the specified collection type mapping) field.

public class Category
{
 public Category() {}
 protected int categoryID;
 protected String categoryName;
 protected List products;
...

public class Product {
    private int pID;
    private int categoryID;
    private List categories;

In class-descriptor of *Category* you need a collection-descriptor point to the indirection table and Product

<collection-descriptor name="products"
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
     element-class-ref="...Product"
     auto-retrieve="true"
     auto-update="object"
     auto-delete="link"
     indirection-table="mycategoryproduct"
  >
     <fk-pointing-to-this-class column="ID"/>
     <fk-pointing-to-element-class column="pid"/>
</collection-descriptor>

In class-descriptor of *Product* you need a collection-descriptor point to the indirection table and Category

<collection-descriptor name="categories"
collection-class="org.apache.ojb.broker.util.collections.ManageableArrayList"
     element-class-ref="...Category"
     auto-retrieve="true"
     auto-update="object"
     auto-delete="link"
     indirection-table="mycategoryproduct"
  >
     <fk-pointing-to-this-class column="pid"/>
     <fk-pointing-to-element-class column="ID"/>
</collection-descriptor>

If you are using the odmg-api, please see take care of mandatory auto-xxx settings
http://db.apache.org/ojb/docu/guides/odmg-guide.html#Specific+Metadata+Settings
you can influence deletion behavior in odmg by setting the 'cascadingDeleteMToN' property (since OJB 1.0.2).
http://db.apache.org/ojb/docu/guides/odmg-guide.html#Configuration+Properties



hth regards, Armin

Thanks a lot

Bikram


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to