I have dug into the OJB code a little bit. I'm looking in this method
of org.apache.ojb.broker.Identity:
private void init(Object objectToIdentify, PersistenceBroker
targetBroker, ClassDescriptor cld)
It looks like the child class (ClientPayrollDeductionPlan) is getting
an id (lets say id=1), and then the parent class
(PayrollDeductionClass) is getting the next id (id=2). The associated
classes (PayPlanAssociation) are using the first id (id=1) for their
foreign key. However when the parent class gets stored in the
database, both it and the child have the second id (id=2), but all of
the associated classes have the foreign key equal to the first one
(1).
I hope that made sense.
Shouldn't the Parent class, and the child class both have the same id?
(They do when they get inserted, but not when the associated class is
getting it's foreign keys assigned).
Am I looking in the right area? Is there anything else I should be looking at?
On Tue, 1 Feb 2005 09:59:17 -0600, Wesley Lemke <[EMAIL PROTECTED]> wrote:
> 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]