Wulf,

Yes, that would work if the Customer isn't also a new object.

When I have:

        Customer customer = new Customer();
        CustomerAddressLink cal = new CustomerAddressLink();
        Address address = new Address();
        cal.setCustomer(customer);
        cal.setAddress(address);

customer.getId() would be null.  Granted I could call broker.store() on the
Customer and Address first. However, with auto-update="true" on the 
references I was hoping I'd be able to just call store on the
CustomerAddressLink, and have OJB or some extension to OJB handle assigning
the foreign keys.

When I set the keys on the CustomerAddressLink to autoincrement then it
works, it appears to generate value for the keys, and before storing assign
the correct foreign keys to the primary key, however when beforeStore is
called on the listeners the keys are incorrect.

This has led me to thing that by replacing the SequenceGenerator I may be
able assign the keys correctly, however marking them as auotincrement seems
weird (but if I can get it to work, I can live with it).

Alan

-----Original Message-----
From: Wulf Wechsung [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 12, 2002 1:46 PM
To: OJB Users List
Subject: AW: Primary Keys that are also Foreign Keys


Hello Alan,

I'd think that usually you'd also set the address and the customer objects
manually for the new association, maybe you could just get the required Id's
from those references and set them manually for the association object, like
this:
{
...
        CustomerAddressLink cal = newCustomerAddressLink();
        cal.setCustomer(customer);
        cal.setCustomerId(customer.getId);

...

}

Sorry, in case this is just stating the obvious but I tend to overlook
obvious things *a lot*

Greetings,
Wulf



-----Urspr�ngliche Nachricht-----
Von: Olmanson, Alan [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 12. Dezember 2002 20:26
An: '[EMAIL PROTECTED]'
Betreff: Primary Keys that are also Foreign Keys


Hello, 

I our application we have link tables where we can not use MtoN
relationships because there is additional data in the table.  

We are using the PB and would like the foreign objects set into the Link
class to determine the key for the class.

So, for example we have a CustomerAddressLink, it has a customerId, an
addressId, a customer, and an address, along with other information.

If I create a new CustomerAddressLink and set the customer and address, the
object is not saved since the primary keys (customerId and addressId) have
not been set and are not auto-incremented.  With 0.9.7 I was able to set the
pk from the foreign objects in the beforeStore event, however with the
current version from CVS it ignores the new id when determining if it has a
valid pk.

Is there a way to do this?

Alan


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

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

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

Reply via email to