Hi,

 

 I facing problem implementing many to many relation in castor.

Castor is creating the object but its not updating the association table.

 

 

The java code I used is as follows:

 

public class castor

{

    private Mapping  _mapping;

    private static JDO  _jdo;

    private Database db;

 

  public castor() throws Exception

  {

        _mapping = new Mapping( getClass().getClassLoader() );

        _mapping.setLogWriter(new PrintWriter(System.out));

        //_mapping.loadMapping("file:///F:/persistence/Mapping.xml");

        _jdo = new JDO();

        _jdo.setLogWriter( new PrintWriter(System.out) );

        _jdo.setConfiguration("file:///F:/persistence/Database.xml");

        _jdo.setDatabaseName("orcl");

        _jdo.setClassLoader(getClass().getClassLoader());

        //_jdo.setDatabasePooling(true);

        db=_jdo.getDatabase();

        //db.setAutoStore(true);

        System.out.println("\nSuccessfully initialized Castor");

 

    Operation o=new Operation();

    o.setDescription("Operation Deep Thought");

    o.setOperationId("3");

    o.setOperationName("Deep Thought");

    db.begin();

    db.create(o);

    dbcommit();

 

    Resource r=new Resource();

    r.setDescription("Space Ship - Event Horizon ");

    r.setResourceId("3");

    r.setResourceName("Event Horizon");

    r.setResourceType("Space Ship");

    db.begin();

    db.create(r);

    db.commit();

 

    Permission p=new Permission();

    p.setDescription("Permission 3 desc");

    p.addOperation(o);

    p.setPermissionId("3");

    p.setPermissionName("Permission 3");

    p.setResource(r);

    db.begin();

    db.create(p);

    db.commit();

 

    db.close();

 

    System.out.println("Successfully created permission object.");

 

 }

 

 

  public static void main(String[] args) throws Exception {

    castor castor1 = new castor();

  }

}

 

 

 

My mapping file is as follows:

 

  <!-- MAPPING FOR OPERATION --> 

 

  <class name=" mypkg.Operation"

         identity="operationId">

    <description>Operation</description>

    <map-to table="OPERATION" xml="Operation" />

    <field name="operationId" type="string" >

      <sql name="OPERATION_ID" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="operationName" type="string" >

      <sql name="OPERATION_NAME" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="Description" type="string" >

      <sql name="OPERATION_DESC" type="char"/>

      <xml node="attribute"/>

    </field>

  </class>

 

 

  <!-- MAPPING FOR RESOURCE --> 

 

  <class name=" mypkg.Resource"

     identity="resourceId">

    <description>Resource</description>

    <map-to table="RESOURCE" xml="Resource" />

    <field name="resourceId" type="string" >

      <sql name="RESOURCE_ID" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="resourceName" type="string" >

      <sql name="RESOURCE_NAME" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="ResourceType" type="string" >

      <sql name="RESOURCE_TYPE" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="Description" type="string" >

      <sql name="RESOURCE_DESC" type="char"/>

      <xml node="attribute"/>

    </field>

  </class>

 

 

 

  <!-- MAPPING FOR PERMISSION --> 

 

  <class name=" mypkg.Permission"

         identity="permissionId">

    <description>Permission</description>

    <map-to table="PERMISSION" xml="Permission" />

    <field name="permissionId" type="string" >

      <sql name="PERMISSION_ID" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="permissionName" type="string" >

      <sql name="PERMISSION_NAME" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="Description" type="string" >

      <sql name="PERMISSION_DESC" type="char"/>

      <xml node="attribute"/>

    </field>

    <field name="resource" type=" mypkg.Resource" >

      <sql name="RESOURCE_ID" />

      <xml node="attribute"/>

    </field>

    <field name="operations" type="mypkg.Operation" required="true"

      collection="vector">

      <sql name="OPERATION_ID"

           many-table="PERM_OPS" many-key="PERMISSION_ID" />

      <xml node="attribute"/>

    </field>

  </class>

 

Regards,

Suresh

Reply via email to