| Andy Jefferson 2005-09-28, 5:46 pm |
| > I've not gone through the data created by the test, only the first few
> records and the fact that it is creating these duplicate records (as I call
> them).
Here's an issue for you Michael. This is the real issue behind our discussion
earlier. Hopefully this simplifies it all :-)
In the schema for "inheritance2" we have the Person class with its own table
CREATE TABLE persons
(
DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY,
...
)
and then we have the subclasses with these tables
CREATE TABLE fulltimeemployees
(
DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY,
...
)
CREATE TABLE parttimeemployees
(
DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY,
...
)
So when a JDO impl wants to insert a FullTimeEmployee object it will try to
insert a row into PERSONS, and the fact that you have IDENTITY on the column
will allocate an id. It will then try to insert into FULLTIMEEMPLOYEES, and
will try to allocate a (possibly different) identity since you have IDENTITY
on that table too!
Only the root table should have IDENTITY specified - in this case PERSONS. The
sub-tables should just be "DATASTORE_IDENTITY INTEGER NOT NULL". This is
correct in the schema for "inheritance3" and "inheritance4", but
"inheritance2" needs a fix.
Returning to the issue of earlier, I had simply seen the above "IDENTITY"
specified on these two tables and raised the issue based on that (without
looking down to find any base table). The above change will mean that the
issue discussed before is likely _not_ going to affect us here since the ids
are actually assigned in the root table (PERSONS), and not in
PARTTIMEEMPLOYEE/FULLTIMEEMPLOYEE tables, and so you won't get clashes of
identity values between FullTime and PartTime employees - the id for a
PartTimeEmployee is assigned in the PERSONS table, and the id for a
FullTimeEmployee is assigned in the PERSONS table also.
Hope that clears it up!
--
Andy
|