Hi everybody,

I am trying to persist a Company object with one Address object and one Discount object (1:1 aggregation for both relationships: Company-Address, Company-Discount). I am using JDO API (Sun's JDO Reference Implementation + OJB's JDO-plugin). That's because I wanted my application to be JDO-compliant. I don't intend to use some other OJB APIs, like PB API.

In order to achieve my goal, first I tried to use nested objects to store this composite object into a single table (i.e. defining address::street, etc. tags into the repository-user.xml file). I manage to insert a company into the DB (BTW: I am using MS SqlServer), with the address and discount also stored into the Company table.
But I had problems retrieving the inserted company from the DB. The problem was that the Addresss and Discount objects were not null themselves, but they had null values for their attributes. The rest of the Company's attributes had the correct values. Do you have any idea why it didn't work?


Since the previous approach didn't work, I tried another one: I gave up using nested objects and I used separate tables for each of the 3 classes. Also, I tried to use a single transaction to commit all 3 objects at once, but again it didn't work. So, I did something like:
PersistenceManager manager = ....
Transaction tx = manager.currentTransaction();
tx.begin();
Company c = new Company();
//populate company fields, except for Address and Discoutn
Address a = new Address();
//populate address fields
Discount d = new Discount();
//populate discount fields
c.setAddress(a);
c.setDiscount(d);
manager.makePesistent(c);
tx.commit();


The problem is that when the code is executed, I get a very strange behavior, which seems to be a little bit random:
- sometimes OJB stores 1 company into the Company table, 1 address into the Address table and 1 discount into the Discount table with the foreign keys set correctly (correct behavior)
- some other times it stores 1 company into the Company table, 2 addresses into the Address table and 1 discount into the Discount table (wrong behavior)
- or 1 company, 1 address, 2 discounts (wrong behavior)
- or 1 company, 2 addresses, 2 discounts. (wrong behavior)
And all this happens by running the same code multiple times. Do you have any idea what's wrong here?


Thanks a lot for your time,
George.


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



Reply via email to