Bill,

You are trying to treat the name column as a PK which it is not.  If you
assign the same food object (same object id and PK) to multiple objects
through a M:N association OJB will only store on row in the food table.

The "solution" you are looking for is to look up the food object in the
table (or create with PK) prior to assigning the food to a person.

Wally

-----Original Message-----
From: Bill Lear [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, January 21, 2003 9:05 AM
To: Armin Waibel
Cc: OJB Users List
Subject: Re: Please Help! Still having problem with simplified
ManyToManyTest


On Tuesday, January 21, 2003 at 10:06:54 (+0100) Armin Waibel writes:
>Hi Bill,
>
>I add your new test cases to CVS. I made some minor modifications.
>Curious, all tests work like designed - test attached, check it out
>please.
>
>> If you comment out the two testMtoNSeparate_XX methods and run the 
>> junit test with testMtoNTogether, the resulting FISH table is:
>
>you add two new fishs --> 2
>
>> If you comment out testMtoNTogether, and run the junit test with the 
>> two testMtoNSeparate_XX methods, the resulting FISH table is:
>
>you add two new fishs per test case --> 4
>
>Did I overlook something?

Thanks very much Armin for your help.  Unfortunately, perhaps I have not
made clear what the problem is.

I want the name column of the FISH table to be treated as unique.  If I
create a Fish named 'tuna', add it to the favoriteFoods of a Gourmet
named 'Bob', and store the Gourmet 'Bob' in a newly created database, I
expect one row to be created in the FISH table with the name column set
to 'tuna'.  If I then, in another run of the program, or in another
program altogether --- wherever --- create another Fish, also named
'tuna', add to the favoriteFoods of a Gourmet named 'Paula' and store
the Gourmet 'Paula' to the same database where 'Bob' is stored, I expect
there still to be only one row in the FISH table --- one for the fish
'tuna'.

Your test case assigns a unique name to the fish by giving them a
timestamp.  So, when you store the fish, you get one row per each fish
you create, your test case passes, but there are 8 rows created in the
FISH table:

%  echo 'select * from FISH;' | mysql ojb
foodId  name                  calories      typeOfWater
1       tuna                  242           salt
3       trout                 52            fresh water
5       trout_1043160480295   52            fresh water
6       tuna_1043160480295    242           salt
7       tuna_1043160480471    242           salt
8       trout_1043160480471   52            fresh water
9       trout_1043160480663   52            fresh water
10      tuna_1043160480663    242           salt

If I change the test case you sent (again, thank you) by removing the
addition of the timestamps to the Fish names, and use only the fish
names 'trout' and 'tuna', the test case fails, and the FISH table is
populated with the same number of rows, with duplicate names:

%  echo 'select * from FISH;' | mysql ojb
foodId  name    calories      typeOfWater
1       tuna    242           salt
3       trout   52            fresh water
5       trout   52            fresh water
6       tuna    242           salt
7       tuna    242           salt
8       trout   52            fresh water
9       trout   52            fresh water
10      tuna    242           salt

What I expect to see is this:

%  echo 'select * from FISH;' | mysql ojb
foodId  name    calories      typeOfWater
1       tuna    242           salt
3       trout   52            fresh water

I just could not figure out how to force OJB to treat the 'name' column
as unique and only store the entry once (again, totally ignoring the
fields calories and typeOfWater).

Does this make sense?  I hope I haven't confused the issue.

Thomas mentioned that perhaps this is a problem in the ODMG layer and
that I should use the PersistenceBroker API.  I can certainly try this,
though I was hoping to use ODMG to avoid the extra work associated with
the PersistenceBroker (i.e., "locking, tracking objects state, object
transactions") mentioned in the FAQ.

One the other hand, if the ODMG layer is not broken in this regard, I
would like to know how to fix my declarations and coding to produce the
result I need (I'm going to have several of these types of tables and I
simply can't afford to have duplicates).  I have tried numerous
combinations of coding changes, changes to the schema and to the
repository definitions, none of which seem to work.

Thanks again Armin for your help (and thanks, too, to Thomas --- any
relation to the famous composer?).


Bill

--
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