Hello Everyone,
I am having some problems using the vector in OJB implementation, every time I
lay my hands on Vector combination I run into problems with one or the other
implementation.
I need some help with following concept
I have two tables
mycategory
ID - primary key
name varchar
myproducts
pid - primary key
prodname
catid -- foriegn key
Now for the classes which we use for mapping purpose
public class Category
{
public Category() {}
protected int categoryID;
protected String categoryName;
public int getcategoryID() { return this.categoryID; }
public String getcategoryName() { return this.categoryName; }
void setcategoryID(int categoryID) { this.categoryID=categoryID; }
void setcategoryName(String categoryName) { this.categoryName=categoryName; }
}
and for product
public class Product {
private int pID;
private int categoryID;
private String pName;
private Category toCategory;
public int getpID() {
return pID;
}
public void setpID(int pID) {
this.pID = pID;
}
public int getcategoryID() {
return categoryID;
}
public void setcategoryID(int categoryID) {
this.categoryID = categoryID;
}
public java.lang.String getpName() {
return pName;
}
public void setpName(java.lang.String pName) {
this.pName = pName;
}
public Category gettoCategory() {
return this.toCategory;
}
public void settoCategory(Category toCategory) {
this.toCategory=toCategory;
}
}
now in repositry.xml
I define
<class-descriptor class="Category" table="mycategory">
<field-descriptor id="1" name="categoryID" column="iID" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor id="2" name="categoryName" column="name" jdbc-type="VARCHAR"
/>
<collection-descriptor name="toProduct" element-class-ref="Product">
<inverse-foreignkey field-id-ref="2"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="Product" table="myproducts">
<field-descriptor id="1" name="pID" column="pid" jdbc-type="INTEGER"
primarykey="true" autoincrement="true"/>
<field-descriptor id="2" name="pName" column="prodname" jdbc-type="VARCHAR" />
<field-descriptor id="3" name="categoryID" column="catid" jdbc-type="VARCHAR"
/>
<reference-descriptor
name="toCategory"
class-ref="Category">
<foreignkey field-id-ref="1"/>
</reference-descriptor>
</class-descriptor>
This works fine with when I fetch and display using the nested library of
struts.
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.
Thanks a lot
Bikram