I had the same problem. I worked around it by calling
pb.retrieveAllReferences(p) right before storing so that the references
get updated from the foreign keys and not vice versa.

- Scott

-----Original Message-----
From: Gallagher, Ron (GEPS Contractor) [mailto:[EMAIL PROTECTED]]

Sent: Thursday, January 23, 2003 2:19 PM
To: 'OJB Users List'
Subject: RE: Problem with setting foreign keys


Sayontan --

The reason that you're ending up with a record in the
tbl_pages_in_module table with null values for fk_pages and the
fk_module is due to how OJB deals with referenced objects.  When you
store an object, PagesInModule in your case, OJB looks at all of the
references that you've defined for the class.  It updates the values on
the object that you're storing with the primary key value(s) from the
referenced object(s).  If the referenced objects are null, as it is in
your case, then the values on the object that you're storing are set to
null.

HTH

Ron Gallagher
Atlanta, GA
[EMAIL PROTECTED]

-----Original Message-----
From: Sinha, Sayontan (IN - India) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 23, 2003 11:00 AM
To: '[EMAIL PROTECTED]'
Subject: Problem with setting foreign keys


Hi,
I have been facing a very strange problem with attempts to update
foreign keys. Let me attempt to describe the scenario.
 
I have a few tables, called tbl_pages, tbl_pages_in_module and
tbl_module. I am using an Oracle 8.1.7 DB.
 
These are the extracts from repository_user.xml for them:
 
<!-- Definitions for com.dc.asctool.lowlevel.Pages -->
<class-descriptor
  class="com.dc.asctool.lowlevel.Pages"
  table="TBL_PAGES"
 >
 
  <field-descriptor id="1"
   name="pagesId"
   column="PK_PAGES"
   jdbc-type="INTEGER"
   primarykey="true"
   autoincrement="true"
  />
 
  <field-descriptor id="2"
   name="pageName"
   column="FLD_PAGE_NAME"
   jdbc-type="VARCHAR"
  />
 
  <collection-descriptor
   name="pagesInModuleHolder"
   element-class-ref="com.dc.asctool.lowlevel.PagesInModule"
  >
   <inverse-foreignkey field-id-ref="2"/>
  </collection-descriptor>
 </class-descriptor>

 
<!-- Definitions for com.dc.asctool.lowlevel.Module -->
<class-descriptor
  class="com.dc.asctool.lowlevel.Module"
  table="TBL_MODULE"
 >
 
  <field-descriptor id="1"
   name="moduleId"
   column="PK_MODULE"
   jdbc-type="INTEGER"
   primarykey="true"
   autoincrement="true"
  />
 
  <field-descriptor id="2"
   name="moduleDescription"
   column="FLD_MODULE_DESCRIPTION"
   jdbc-type="VARCHAR"
  />
 
  <collection-descriptor
   name="pagesInModuleHolder"
   element-class-ref="com.dc.asctool.lowlevel.PagesInModule"
  >
   <inverse-foreignkey field-id-ref="3"/>
  </collection-descriptor>
 </class-descriptor>
 
 
<!-- Definitions for com.dc.asctool.lowlevel.PagesInModule -->
<class-descriptor
  class="com.dc.asctool.lowlevel.PagesInModule"
  table="TBL_PAGES_IN_MODULE"
 >
 
  <field-descriptor id="1"
   name="pagesInModuleId"
   column="PK_PAGES_IN_MODULE"
   jdbc-type="INTEGER"
   primarykey="true"
   autoincrement="true"
  />
 
  <field-descriptor id="2"
   name="pagesId"
   column="FK_PAGES"
   jdbc-type="INTEGER"
  />
 
  <field-descriptor id="3"
   name="moduleId"
   column="FK_MODULE"
   jdbc-type="INTEGER"
  />
 
  <reference-descriptor
   name="pages"
   class-ref="com.dc.asctool.lowlevel.Pages"
  >
   <foreignkey field-id-ref="2"/>
  </reference-descriptor>
 
  <reference-descriptor
   name="module"
   class-ref="com.dc.asctool.lowlevel.Module"
  >
   <foreignkey field-id-ref="3"/>
  </reference-descriptor>
 </class-descriptor>
 
 
Within a small piece of code, this is what I do:
 
        try {
            PagesInModule p = new PagesInModule();
            p.setPagesId(new Integer(3));
            p.setModuleId(new Integer(1));
            pb.beginTransaction();
            pb.store(p);
            pb.commitTransaction();
        }
        catch (PersistenceBrokerException pbe) {
            s_log.error("Could not do it.", pbe);
        }

I do have a row in tbl_pages with pk_pages = 3 and a row in tbl_module
with pk_module = 1.
 
What happens as a result of this is that I get a row in
tbl_pages_in_module with a new pk_pages_in_module_id and null in the
fk_pages and the fk_module columns.
 
I will be greatly obliged if anyone can shed any light on why this might
be happening. I am using OJB version 0.9.8.
 
Regards,
Sayontan.
 
-- 
Sayontan Sinha
 

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


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

Reply via email to