I have class DataProducer which contains a reference to class Person as 'contact'. 
Also have class Deployment that extends DataProducer which has a reference to a class 
Device

I am only to able to update a DataProducer instance's 'contact' field, but only if I 
queried it as a Deployment and then upcast
it to a DataProducer.   

If Ive OQL'd for a DataProducer that happens to also be a Deployment, I get errors as 
below...

>>>[java] org.exolab.castor.jdo.DataObjectAccessException: Type conversion error: 
>>>could not set null to FieldMolder of myapp.Deployment.setdevice(myapp.Device device)
>>>
>>>[java] [ssds_test] org.exolab.castor.jdo.TransactionAbortedException: Nested error: 
>>>java.lang.IllegalArgumentException: object is not an instance of declaring class
    
How do I need to modify my mapping or classes so can i correctly operate on any 
DataProducer class... do I need to downcast to the correct instance of someplace????

Thanks in advance for any help!
Rich Schramm



<!-- **************************************** -->
<!--  Mapping for DataProducer  -->
<!-- **************************************** -->

  <class name="myapp.DataProducer"
     identity="id"
     key-generator="UniqueID">

    <map-to table="DataProducer" />

    <field name="id" type="integer">
      <sql name="id" type="integer" />
    </field>
    
    <field name="name" type="string">
      <sql name="name" type="char" />
    </field>

    <field name="contact" type="myapp.Person">
      <sql name="ownerID_FK"/>
    </field>
    
    <field name="someEvents" type="myapp.SomeEvent"
           collection="collection">
      <sql many-key="DataProducerID_FK"/>
    </field>
    
    <!-- DataProducer has reference to ResourceFile with many-many relationship -->
    <field name="resourceFiles" type="myapp.ResourceFile"  collection="collection" >
      <sql name="ResourceID_FK"
           many-table="DataProducerAssocResource" many-key="DataProducerID_FK" />
    </field>

     <!-- DataProducer has list of its DataContainers -->
     <field name="dataContainers" type="myapp.DataContainer" 
           collection="collection"  >
      <sql many-key="DataProducerID_FK"/>
     </field>


  </class>

  <!-- **************************************** -->
<!--  Mapping for Deployment, extending DataProducer  -->
<!-- **************************************** -->
<!--  extends="myapp.DataProducer"  uses that key generator -->

  <class name="myapp.Deployment"
     extends="myapp.DataProducer"  identity="id"  >

    <map-to table="Deployment" />

    <field name="id" type="integer">
      <sql name="id" type="integer" />
    </field>

    <field name="device" type="myapp.Device">
      <sql name="DeviceID_FK"/>
    </field>

     <field name="parent"
           type="myapp.Deployment"
          
           >
        <sql name="parent_id"
             many-table="DeploymentParentChild"
             many-key="child_id" 
             />
    </field>
    
  
    <field name="children"
           type="myapp.Deployment"
           collection="collection"
           set-method="setChildren"
           get-method="getChildren"
           lazy="true" >
      <sql name="child_id"
           many-table="DeploymentParentChild"
           many-key="parent_id"
           />
    </field> 

  </class>

<!-- **************************************** -->
<!--  Mapping for Device  -->
<!-- **************************************** -->

  <class name="myapp.Device"
         identity="id" 
         key-generator="UniqueID">
<cache-type type="count-limited" capacity="100"/>
    <map-to table="Device" />

    <field name="id" type="integer">
      <sql name="id" type="integer" />
    </field>

    <field name="contact" type="myapp.Person">
      <sql name="ownerID_FK" />
    </field>

    <field name="name" type="string">
      <sql name="name" type="char" />
    </field>
    
    <field name="type" type="string">
      <sql name="type" type="char" />
    </field>

     <field name="deployments" type="myapp.Deployment" 
           collection="collection">
        <sql many-key="DeviceID_FK"/>
     </field>

    <!-- Device has reference to ResourceFile with many-many relationship -->
    <field name="resourceFiles" type="myapp.ResourceFile"  collection="collection">
      <sql name="ResourceID_FK"
           many-table="DeviceAssocResource" many-key="DeviceID_FK" />
    </field>


  </class>

<!-- **************************************** -->
<!--  Mapping for Person  -->
<!-- **************************************** -->

  <class name="myapp.Person" identity="id" key-generator="UniqueID" >
    <cache-type type="unlimited" />
   <!-- <cache-type="unlimited" />  -->
    <map-to table="Person" />
    <field name="id" type="integer">
      <sql name="id" type="integer"/>
    </field>

    <field name="name" type="string">
      <sql name="name" type="char" dirty="check" />
    </field>

  </class>



/****************** java for class DataProducer **********/

package myapp;

import java.util.Collection;
import java.util.ArrayList;
import java.util.Date;

import org.exolab.castor.jdo.*; // for jdo timestamp interface

public class DataProducer implements TimeStampable {

   /*** manage data containers for this data producer ***/
    public void addDataContainer( DataContainer dc) {
        _datacontainers.add(dc);
        dc.setDataProducer(this);
    }
    public Collection getDataContainers() {
       return new ArrayList(_datacontainers);
    }
    public DataContainer createDataContainer() { return new DataContainer(); }

    /*** end  manage data containers for this data producer ***/

    public int getId(){ return _id; }
    public void setId(int id){ _id = id; }

    public Person getContact(){ return _contact; }
    public void setContact(Person contact){ _contact = contact; }

    public Date getStartDate(){ return _startDate; }
    public void setStartDate(Date startDate){ _startDate = startDate; }

    public Date getEndDate(){ return _endDate; }
    public void setEndDate(Date endDate){ _endDate = endDate; }

    public String getName(){
     return _name;
    }

    public void setName(String s){
        _name = s;
    }

    /*** manage event list for this data producer ***/
    public void addSomeEvent( SomeEvent e) {
        _events.add(e);
        e.setDataProducer(this);
    }
    public Collection getSomeEvents() {
       return new ArrayList(_events);
    }
    public SomeEvent createSomeEvent() { return new SomeEvent (); }
    /*** end manage event list for this data producer ***/


    /*** manage ResourceFile list for this data producer ***/

    public Collection getResourceFiles() { return new ArrayList(_resources); }

    public void addResourceFile( ResourceFile r )
    {
        if ( ! _resources.contains( r ) ) {
            _resources.add( r );
            r.addDataProducer( this );
        }
    }


    /*** end ResourceFile list for this data producer ***/


    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("(DataProducer Id#: " + _id + ") Name: "+ _name);
        sb.append("- a generic DataProducer" );
        return sb.toString();
    }

  /**
    * The timeStamp value.  Used for Long Transactions in Castor.
    */
    private long _timeStamp;
    public long jdoGetTimeStamp() { return _timeStamp; }
    public void jdoSetTimeStamp(long p1){ _timeStamp = p1; }

    protected int _id;
    private Person _contact;
    private Date _startDate;
    private Date _endDate;
    protected String _name;
    private Collection _datacontainers = new ArrayList();
    private Collection _resources = new ArrayList();
    private Collection _events = new ArrayList();

}  //end class definition

/****************** java for class Deployment**********/
package myapp;


import java.util.Collection;
import java.util.ArrayList;

public class Deployment extends DataProducer {

    // overide default constructor to sets the parent,
    // and add self to the parents child list
    public Deployment() { this( null, null ); } 

    public Deployment(  Device device, Deployment parent )
    {
      _parent = parent;
      _device = device;
      if( device != null) device.addDeployment(this);
      _children= new ArrayList(); 
      
      if( device != null) device.addDeployment(this); //else error? 
      if( parent != null ) parent.addChild( this );  //not root
    }
    // end constuctors

    public Device getDevice(){  return _device;  }
    public void setDevice(Device device){ _device = device;}        
            
    //jdo required functions to manage lists
 
    public Deployment getParent(){ return _parent; }
    
    public void setParent( Deployment parent )
    {
    _parent = parent;
    }      
            
    public Collection getChildren(){ return new ArrayList( _children ); }
    public void setChildren( Collection childrenList )
    { _children = new ArrayList( childrenList ); }
    
    public void addChild( Deployment child )
    {
       _children.add( child );
       child.setParent( this );
    }
    
    // end jdo required...

    public String toString() {
        StringBuffer sb = new StringBuffer();
         sb.append("(Deployment Id#: " + _id + ")");
        
        return sb.toString();
    }

    private Device _device;    
    private Deployment _parent;
    private Collection _children = new ArrayList();

}
/****************** java for class Device**********/
package myapp;

import java.util.Collection;
import java.util.ArrayList;

import org.exolab.castor.jdo.*; //for jdo timestamp interface

public class Device implements TimeStampable {



    public int getId() { return _id; }
    public void setId(int id) { _id = id; }

    public String getName() { return _name; }
    public void setName(String name) { _name = name; }

    public Person getContact() { return _contact; }
    public void setContact(Person contact) { _contact = contact; }

    public String getType(){ return _type; }
    public void setType(String t){ _type = t; }

   /*** manage deployments for this device ***/
    public void addDeployment( Deployment d ) {
        _deployments.add( d );
        d.setDevice(this);
    }

    public Collection getDeployments() {
       return new ArrayList(_deployments);
    }

    public Deployment createDeployment() { return new Deployment(); }

    /*** end manage deployments for this device ***/


    /*** manage resources for this device ***/

/*******    public Collection getResources() { return new ArrayList( _resources); }

    public void addResource( Resource r )
    {
        if ( ! _resources.contains( r ) ) {
            _resources.add( r );
            r.addDevice( this );
        }
    }
********/
    public Collection getResourceFiles() { return new ArrayList(_resources); }

    public void addResourceFile( ResourceFile r )
    {
        if ( ! _resources.contains( r ) ) {
            _resources.add( r );
            r.addDevice( this );
        }
    }

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("(Device Id#: " + _id + ")");
        return sb.toString();
    }

  /**
    * The timeStamp value.  Used for Long Transactions in Castor.
    */
    private long _timeStamp;
    public long jdoGetTimeStamp() { return _timeStamp; }
    public void jdoSetTimeStamp(long p1){ _timeStamp = p1; }

    private int _id;
    private String _name;
    private Person _contact;

    private Collection _deployments = new ArrayList();
    private Collection _resources = new ArrayList();
    private String _type;
} //end class definition

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to