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 "Weaver, Scott" <Sw...@rippe.com> on 2003/06/18 23:34:55 UTC
1:n not setting FK in n objects when n object has a reference bac
k to 1
This is a strange one, or maybe I'm just being ignorant.
STEP 1: I define a collection descriptor within PortletApplactionDefinition to the PortletDefinition. Everything runs as expected with the mapping below. Adding PortletDefinitions to the "portlets" collection in PortletApplication correctly sets the "appId" FK within each assoc. PortletDefinition and the DB insert/update goes as expected.
<class-descriptor class="org.apache.jetspeed.om.common.portlet.BasePortletApplicationDefinition" table="PORTLET_APPLICATION">
<field-descriptor
name="id"
column="APPLICATION_ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
conversion="org.apache.jetspeed.util.ojb.ObjectIDtoLongFieldConversion"
/>
...Other mappings left out for brevity
<collection-descriptor
name="portlets"
element-class-
ref="org.apache.jetspeed.om.common.portlet.BasePortletDefinition"
collection-
class="org.apache.jetspeed.om.common.portlet.BasePortletDefinitionList"
>
<inverse-foreignkey field-ref="appId"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor
class="org.apache.jetspeed.om.common.portlet.BasePortletDefinition"
table="PORTLET_DEFINITION"
>
<field-descriptor
name="id"
column="ID"
jdbc-type="INTEGER"
primarykey="true"
autoincrement="true"
conversion="org.apache.jetspeed.util.ojb.ObjectIDtoLongFieldConversion"
/>
<field-descriptor
name="appId"
column="APPLICATION_ID"
jdbc-type="INTEGER"
conversion="org.apache.jetspeed.util.ojb.ObjectIDtoLongFieldConversion"
/>
...Other mappings left out for brevity
</class-descriptor>
STEP 2: If I now add a reference descriptor to PortletDefinition pointing back to the PortletApplicationDefinition like this:
<reference-descriptor name="app" class-ref="org.apache.jetspeed.om.common.portlet.BasePortletApplicationDefinition" >
<foreignkey field-ref="appId"/>
</reference-descriptor>
the FK "appId" is NOT set and causes a DB failure as the appId is null, which is not allowed.
Now if I go back in, remove the reference descriptor and re-run the test, everything works fine.
What am I doing wrong here? Or is what I am doing not even allowed, which I hope is not the case.
Thanks,
*===================================*
* Scott T Weaver *
* Jakarta Jetspeed Portal Project *
* weaver@apache.org *
*===================================*