You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Johan Gellner <jo...@printon.com> on 2004/11/18 14:42:05 UTC
Only one element is returned in m:n collections
Hi!
I'm new to OJB but have read most tutorials. I have a very strange
problem that I would like some help with. I am currently using OJB
1.0.rc5.
In the database I have three tables: PRODUCT, REFERER and PRODREFMAP.
The last table is an indirection table and contains only two columns:
PRODUCT_ID and REFERER_ID and thus implements the m:n mapping between
products and referrers.
I have created the Java classes for PRODUCT and REFERER, where
Referer.java contains a Collection named "products" and Product.java
contains a Collection named "referers".
The class-descriptor for Referer looks like this:
<class-descriptor
class="somepackage.Referer"
table="REFERER">
. . .
<collection-descriptor
name="products"
collection-class="org.apache.ojb.broker.util.collections.ManageableArray
List"
element-class-ref="somepackage.Product"
auto-delete="false"
auto-retrieve="true"
orderby="name"
sort="DESC"
indirection-table="PRODREFMAP">
<fk-pointing-to-this-class column="REFERER_ID"/>
<fk-pointing-to-element-class column="PRODUCT_ID"/>
</collection-descriptor>
</class-descriptor>
In my code, I successfully obtain an instance of Referer "r" from the
database through ODMG API. I then call r.getProducts() but the
Collection I get back only contains ONE Product element although the
database contains several Products for that Referer (as expressed in the
indirection table):
PRODREFMAP (table example)
----------------------------------------------
PRODUCT_ID REFERER_ID
3002 1
3003 1
3004 1
(but only product with id 3002 is returned)
Any idea why this is so?
Any help would be greatly appreciated!
Regards,
Johan Gellner