Hi there:

I am just learning OJB and so far I think its great! I am having some problems 
inserting 1:1 records that I was hoping someone could help me with. I have a table 
Transactions that has a reference (1:1) to a table Payments:

Transactions
transactionid (pk)
paymentid (fk)

Payments
paymentid (pk)

These therefore correspond to my entity classes like so:

Transactions
long transactionid;
long paymentid;
Payments thePayment;

Payments
long paymentid;

In my repository_user file  have the following:

<class-descriptor class="Transactions" table="Transactions">
    <field-descriptor id="0" name="transactionid" column="TransactionID" 
jdbc-type="INTEGER" primarykey="true" access="readonly"/>
    ......
    <field-descriptor id="17" name="paymentid" column="PaymentID" jdbc-type="INTEGER" 
/>
    <reference-descriptor name="thePayment" class-ref="Payments" auto-update="false">
        <foreignkey field-ref="paymentid"/>
    </reference-descriptor>
</class-descriptor>
and 

<class-descriptor class="Payments" table="Payments">
    <field-descriptor id="0" name="paymentid" column="PaymentID" jdbc-type="INTEGER" 
primarykey="true" access="readonly" />
    .....
</class-descriptor>

The access=readonly is because I am using MSSQL and need to use the autoincrement for 
the primary key field used by the database (as I also have legacy systems working from 
the same database). When I try to do an insert on the 1:1 mapping above I get a 
payment record created and a transaction record created successfully but the paymentid 
in the transaction record is 0. Can anyone see why this would happen. I have gone 
through all my mappings with a fine tooth comb and also checked to see if any others 
are having the same problem. I am using ODMG (therefore I have set the 
auto-update=false in the reference desciptor as recommended). I would appreciate any 
help anyone has on this!

Thanks
Fiona

Reply via email to