Hi all,

I'm having a bit of trouble with a non-decomposed m:n relationship
using
OJB with mysql.  This is my first time using OJB, so I'm not sure what
I'm missing.  I checked out tutorial 3
(http://db.apache.org/ojb/tutorial3.html#mapping%20m:n%20associations)
and just lifted most of the stuff there.

I have a user object, who can have multiple sponsors.  Sponsors have
multiple users.  The behaviour I'm seeing is that the sponsors
collection
of a user is simply empty.  I'm pulling this user by doing a
getObjectByQuery() call.

My tables are populated by loading text data (so I haven't needed to
call store() yet).  I've bounced tomcat whenever I reload the database
to make sure that OJB doesn't have anything cached.

I'm running on tomcat 4.1.24.  From the OJB.properties, it looks like
I'm
running 0.9.8 of OJB (I didn't install it).  I'm running against mysql
3.23.56.

I turned on debugging and the sql statements to pull in the sponsors
seem
to be called:
-----------------
[org.apache.ojb.broker.accesslayer.JdbcAccess] DEBUG: executeQuery :
Query
from
TABLE_USER_SPONSOR where [EMAIL PROTECTED]
[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG:
SQL:
SELECT
A0.MARKET_ID,A0.BUSINESS_TYPE_ID,A0.COMPANY_PHONE,A0.BRAND_MANAGER_NAME,A0.SPONSOR_TYPE_ID,A0.COMPANY_ADDRESS,A0.COMPANY_NAME,A0.SPONSOR_ID,A0.SHORT_BRAND_NAME
FROM TABLE_SPONSOR A0,TABLE_USER_SPONSOR WHERE
(TABLE_USER_SPONSOR.USERID =
? ) AND TABLE_USER_SPONSOR.SPONSOR_ID = A0.SPONSOR_ID
[org.apache.ojb.broker.accesslayer.JdbcAccess] DEBUG: executeQuery :
ReportQuery from class com.nearbuyhomes.model.bean.SponsorBean count(*)
where [EMAIL PROTECTED]
[org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG:
SQL:
SELECT count(*) FROM TABLE_SPONSOR A0,TABLE_USER_SPONSOR WHERE
(TABLE_USER_SPONSOR.USERID =  ? ) AND TABLE_USER_SPONSOR.SPONSOR_ID =
A0.SPONSOR_ID
-----------------

There doesn't seem to be any problem with getting any of the other
attributes of the user bean (I can get firstName easily enough).

I'm using the PersistanceBroker API.  I don't see any errors in the
logs.
I've thought about decomposing the relationship, but I'd rather not,
since
there's nothing in the relationship that needs to go into the join
table.

I've looked on google, and also searched the mail archive at
mail-archive.com.  But I've found nothing that I thought applicable.

Here are my table def'ns:
---------------------
CREATE TABLE TABLE_NEARBUY_USER(
        USERID INT NOT NULL,
...
);

CREATE TABLE TABLE_SPONSOR (
        SPONSOR_ID int NOT NULL PRIMARY KEY,
        COMPANY_NAME varchar(150) NOT NULL,
...
);

CREATE TABLE TABLE_USER_SPONSOR (
        USERID int NOT NULL,
        SPONSOR_ID int NOT NULL
);
---------------------

And here is the entries in the repository_nearbuy.xml:
---------------------
  <class-descriptor
    class="com.nearbuyhomes.model.bean.NearbuyUserBean"
    table="TABLE_NEARBUY_USER"
  >
    <field-descriptor id="1"
      name="userId"
      column="USERID"
      jdbc-type="INTEGER"
      autoincrement="true"
    />
....
     <collection-descriptor
         name="sponsors"
         element-class-ref="com.nearbuyhomes.model.bean.SponsorBean"
         auto-retrieve="true"
         auto-update="true"
         indirection-table="TABLE_USER_SPONSOR"
      >
        <fk-pointing-to-this-class column="USERID"/>
         <fk-pointing-to-element-class column="SPONSOR_ID"/>
      </collection-descriptor>
  </class-descriptor>

  <class-descriptor
    class="com.nearbuyhomes.model.bean.SponsorBean"
    table="TABLE_SPONSOR" >
    <field-descriptor id="1"
      name="sponsorID"
      column="SPONSOR_ID"
      jdbc-type="INTEGER"
      primarykey="true"
      autoincrement="true"
    />
....
     <collection-descriptor
         name="users"
        
element-class-ref="com.nearbuyhomes.model.bean.NearbuyUserBean"
         auto-retrieve="true"
         auto-update="false"
         indirection-table="TABLE_USER_SPONSOR"
      >
         <fk-pointing-to-this-class column="SPONSOR_ID"/>
         <fk-pointing-to-element-class column="USERID"/>
      </collection-descriptor>

  </class-descriptor>
---------------------

Any help would be appreciated!

Thanks,
Dan


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

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

Reply via email to