I can't seem to get self-referential relationships to work. I was wondering if I
had a design or modeling problem.
I am trying to model the following.
-----------------------------------------------------------------------------------------------------
Description of classes:
UserScenario: can contain a list of WebResources
( UserScenarioWebResource ) , encapsulates a list of Web
pages
WebResource: can contain a list of
WebResources( WebResourceRelation ), encapsulates a Web
Page.
UserScenarioWebResource: extends WebResource,
encapsulates a top-level Web Page.
WebResourceRelation: extends WebResource,
encapsulates a sub-requests ( images, frames).
------------------------------------------------------------------------------------------------------
Database Schema. create table user_scenario (user_scenario_id into not null primary key, user_scenario_name varchar(30) not null );
create table web_resource (
web_resource_id int not null primary key, user_scenario_id int not null, parent_web_resource_id int, name varchar(20), url varchar(100) not null, FOREIGN KEY (user_scenario_id)
REFERENCES user_scenario(user_scenario_id)
); create table user_scenario_web_resource(
web_resource_id int, user_scenario_id int, FOREIGN KEY (user_scenario_id)
REFERENCES user_scenario(user_scenario_id)
); create web_resource_relation ( web_resource_id int, parent_web_resource_id int ); ----------------------------------------------------------------------------------------------------------------- Mapping file.
<mapping>
<!-- User Scenario
-->
<class
name="com.opendemand.jdo.UserScenario" auto-complete="false"
identity="userScenarioId"
key-generator="MAX">
<description>Default mapping for class com.opendemand.jdo.UserScenario</description> <map-to table="user_scenario"/> <field name="userScenarioId" type="integer" > <sql name="user_scenario_id" type="integer"/> </field> <field name="userScenarioName" type="string" > <sql name="user_scenario_name" type="char" /> </field>
<field name="webResources"
type="com.opendemand.jdo.UserScenarioWebResource"
collection="arraylist" get-method="getWebResources" set-method="setWebResources"> <sql many_key="user_scenario_id"/> </field> </class> <!-- Web
Resource-->
<class name="com.opendemand.jdo.WebResource" identity="webResourceId" key-generator="MAX"> <description>Default mapping for class com.opendemand.jdo.WebResource</description> <map-to table="web_resource" /> <field name="webResourceId" type="integer"> <sql name="web_resource_id" type="integer" /> </field> <field name="parentWebResource" type="com.opendemand.jdo.WebResource"> <sql name="parent_web_resource_id" /> </field> <field name="userScenario" type="com.opendemand.jdo.UserScenario"> <sql name="user_scenario_id" /> </field> </class> <class
name="com.opendemand.jdo.UserScenarioWebResource" identity="webResourceId"
depends="com.opendemand.jdo.UserScenario"
extends="com.opendemand.jdo.UserScenarioWebResource">
<description>Default mapping for class com.opendemand.jdo.UserScenario</description> <map-to table="user_scenario_web_resource"/> <field name="webResourceId" type="integer"> <sql name="web_resource_id" type="integer" /> </field> <field name="userScenario" type="com.opendemand.jdo.UserScenario"> <sql name="user_scenario_id" /> </field> </class> <class name="com.opendemand.jdo.WebResourceRelation" identity="webResourceId"
depends="com.opendemand.jdo.UserScenario"
extends="com.opendemand.jdo.WebResource">
<description>Default mapping for class com.opendemand.jdo.WebResourceRelation</description> <map-to xml="web-resource" table="user_scenario_web_resource"/> <field name="webResourceId" type="integer" > <sql name="web_resource_id" type="integer" /> </field> <field name="parentWebResource" type="com.opendemand.jdo.WebResource" > <sql name="parent_web_resource_id" /> </field> </class> </map> ----------------------------------------------------------------------------------------------------------------
I can't seem to get this to work. The user_scenario and the
user_scenario_web_resource tables get populated but not the rest of the tables.
Any ideas or suggestions on how to model this would be greatly
appreciated.
Steve
|