Okay. I found my solution. For self-referential relationship I just use null and don't use read-only field. In my case UserScenarioRelation.childUserScenario == null self-referential relationship.
<class name="com.opendemand.jdo.UserScenarioRelation" identity="id" depends="com.opendemand.jdo.UserScenario" > <map-to table="user_scenario_relation" /> <cache-type type="none" /> <field name="id" type="integer" required="true" > <sql name="id" /> </field> <field name="userScenario" type="com.opendemand.jdo.UserScenario"> <sql name="user_scenario_id" dirty="ignore" /> </field> <!-- a null value represents a self-referential value --> <field name="childUserScenario" type="com.opendemand.jdo.UserScenario"> <sql name="child_user_scenario_id" dirty="ignore" /> </field>. ----- Original Message ----- From: Stephen Ince To: [email protected] Sent: Wednesday, September 26, 2007 6:46 PM Subject: [castor-user] self-referential and read-only I am trying to implement a self-referential relationship. I almost having it working. Question: How do tell castor not todo an update on a column? The column is basically for reads and inserts. When I try doing an insert, the read-only column value is null and it is not being inserted. UserScenario class <-----> UserScenario class. (many-to-many) I model it using an intermediate class to contain the relationship, UserScenarioRelation. UserScenario ---> UserScenarioRelationship. The UserScenarioRelationship.childUserScenario and UserScenarioRelationship.userScenario are not being set when the field is set to 'read-only'. If don't set read-ony="true" castor will try to recursively load (UserScenario) classes in the transaction and subsequently throw a "class not loaded in transaction exception" Here is my mapping file: <class name="com.opendemand.jdo.UserScenario" auto-complete="false" identity="userScenarioId" key-generator="MAX"> <map-to table="user_scenario"/> <field name="userScenarioRelations" type="com.opendemand.jdo.UserScenarioRelation" collection="arraylist"> <sql many-key="user_scenario_id" dirty="ignore" /> </field> </class> <class name="com.opendemand.jdo.UserScenarioRelation" identity="id" depends="com.opendemand.jdo.UserScenario" > <map-to table="user_scenario_relation" /> <cache-type type="none" /> <field name="id" type="integer" required="true" > <sql name="id" /> </field> <!-- these field only get inserted, no updates --> <field name="userScenario" type="com.opendemand.jdo.UserScenario"> <sql name="user_scenario_id" read-only="true" dirty="ignore" /> </field> <!-- these field only get inserted, no updates --> <field name="childUserScenario" type="com.opendemand.jdo.UserScenario"> <sql name="child_user_scenario_id" read-only="true" dirty="ignore" /> </field>. .. </class>

