Hi again, I tried some variations of the code so as to reference the objects whose PKs I am accessing.
This is how the first version of my code now looks like: try { PagesInModule p = new PagesInModule(); Criteria crit = new Criteria(); crit.addEqualTo("pagesId", new Integer(3)); Query q = new QueryByCriteria(Pages.class, crit); Pages pg = (Pages)pb.getObjectByQuery(q); s_log.info(pg); crit = new Criteria(); crit.addEqualTo("moduleId", new Integer(1)); q = new QueryByCriteria(Module.class, crit); Module md = (Module)pb.getObjectByQuery(q); s_log.info(md); p.setPagesId(pg.getPagesId()); p.setModuleId(md.getModuleId()); pb.beginTransaction(); pb.store(p); pb.commitTransaction(); } catch (PersistenceBrokerException pbe) { s_log.error("Could not do it.", pbe); } Here the code still refuses to work correctly (in V 0.9.8. It works in V 0.9.7 according to my expectations). I try setting the id AFTER bringing the objects into the PB's cache. The result is a row in tbl_pages_in_module with null for the fk_pages and fk_modules entries. So I tried this second version: try { PagesInModule p = new PagesInModule(); Criteria crit = new Criteria(); crit.addEqualTo("pagesId", new Integer(3)); Query q = new QueryByCriteria(Pages.class, crit); Pages pg = (Pages)pb.getObjectByQuery(q); s_log.info(pg); crit = new Criteria(); crit.addEqualTo("moduleId", new Integer(1)); q = new QueryByCriteria(Module.class, crit); Module md = (Module)pb.getObjectByQuery(q); s_log.info(md); p.setPages(pg); p.setModule(md); pb.beginTransaction(); pb.store(p); pb.commitTransaction(); } catch (PersistenceBrokerException pbe) { s_log.error("Could not do it.", pbe); } Here I set the OBJECTS themselves instead of the ids. Now it works! Now that I have got the code working, I get back to my question. Have there been some major changes between versions 0.9.7 and 0.9.8 so as to prevent things working the same way? Regards, Sayontan. -- Sayontan Sinha ____________________________________________ -----Original Message----- From: Sinha, Sayontan (IN - India) Sent: Friday, January 24, 2003 11:09 AM To: OJB Users List Subject: RE: Problem with setting foreign keys Ron, I tried out my piece of code with OJB 0.9.7 instead of 0.9.8 there. It works like a charm. I will try creating objects in the persistence broker as you have suggested. In the meanwhile, is it a bug that it works in 0.9.7 while it shouldn't? Regards, Sayontan. -- Sayontan Sinha ____________________________________________ -----Original Message----- From: Gallagher, Ron (GEPS Contractor) [mailto:[EMAIL PROTECTED]] Sent: Friday, January 24, 2003 12:49 AM 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]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>