We have a a problem with OJB assigning incorrect id's.  This is the situation:

public class PayrollDeductionPlan {
        Long id;
        String genericInfo = "Generic";
        // List of PayPlanAssociations....
        List assocs = new ArrayList();
}

public class ClientPayrollDeductionPlan extends PayrollDeductionPlan {
        Long id;
        String clientInfo = "Client";
}

public class PayPlanAssociation {
        Long id;
        // Reference to PayRollDeductionPlan
        PayrollDeductionPlan plan;
}

Here is the repository.xml file:

<class-descriptor
          class="model.PayrollDeductionPlan"
          table="dexa810t"
   >
      <field-descriptor
         name="id"
         column="a_id"
         jdbc-type="BIGINT"
         primarykey="true"
         autoincrement="true"
      />    
      <field-descriptor
        name="genericInfo"
        column="generic_info"
                jdbc-type="VARCHAR"
      />
     <collection-descriptor
        name="assocs"
        element-class-ref="model.PayPlanAssociation"
        auto-delete="true"
        auto-update="true"
      >
                <inverse-foreignkey field-ref="plan" />
      </collection-descriptor>
    </class-descriptor>

<class-descriptor
        class="model.ClientPayrollDeductionPlan"
        table="dexa820t"
        >
        <field-descriptor
                name="id"
                column="b_id"
                jdbc-type="BIGINT"
                primarykey="true"
                autoincrement="true"
        />
        <field-descriptor
                name="clientInfo"
                column="client_info"
                jdbc-type="VARCHAR"
        />
        <reference-descriptor name="super"
        class-ref="model.PayrollDeductionPlan"
        auto-retrieve="true"
        auto-update="true"
        auto-delete="true"
    >
        <foreignkey field-ref="id"/>
    </reference-descriptor>
</class-descriptor>

<class-descriptor
        class="model.PayPlanAssociation"
        table="dexa830t"
        >
        <field-descriptor
                name="id"
                column="d_id"
                jdbc-type="BIGINT"
                primarykey="true"
                autoincrement="true"
        />
      <field-descriptor
         name="plan"
         column="a_id"
         jdbc-type="BIGINT"
         access="anonymous"
      />
      <reference-descriptor name="plan" class-ref="model.PayrollDeductionPlan">
        <foreignkey field-ref="plan"/>
      </reference-descriptor>
</class-descriptor>             


When I do something like this:  

PersistenceBroker broker =
PersistenceBrokerFactory.createPersistenceBroker("default", user,
password);
        
        
broker.beginTransaction();      
// Create new ClientPayrollDeductionPlan        
ClientPayrollDeductionPlan plan = new ClientPayrollDeductionPlan();
// Add 5 PayPlanAssociations to this PayrollDeductionPlan
for(int i = 0; i < 5; i++){
    // Create new PayPlanAssociation
    PayPlanAssociation ppa = new PayPlanAssociation();
    // Create link between PayPlanAssociation and PayrollDeductionPlan
    plan.getAssocs().add(ppa);
    ppa.setPlan(plan);
}
broker.store(plan);
broker.commitTransaction();
broker.close();



This is what I get in the tables:  

mysql> select * from dexa810t;  (PayrollDeductionPlan)
+------+--------------+
| a_id | generic_info |
+------+--------------+
|   -3 | Generic      |
+------+--------------+
1 row in set (0.05 sec)

mysql> select * from dexa820t;  (ClientPayrollDeductionPlan);
+------+-------------+
| b_id | client_info |
+------+-------------+
|   -3 | Client      |
+------+-------------+
1 row in set (0.00 sec)

mysql> select * from dexa830t;   (PayPlanAssociation)
+------+------+
| d_id | a_id |
+------+------+
|   -4 |   -2 |
|   -5 |   -2 |
|   -6 |   -2 |
|   -7 |   -2 |
|   -8 |   -2 |
+------+------+
5 rows in set (0.03 sec)


The foreign key in the PayPlanAssociation table is always one off from
what it should be... (-2 instead of -3).  This problem happens in both
MySQL and DB2.

Am I doing something wrong?

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to