db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Jefferson <a...@jpox.org>
Subject Inheritance test schema 2 : "subclass-table" and "identity" strategy
Date Tue, 27 Sep 2005 18:56:08 GMT
The Schema 2 inheritance test provokes a question regarding 
autoassign/identity strategy when using "subclass-table" strategy. We have 3 
classes Employee, PartTimeEmployee, FullTimeEmployee. The Employee class uses 
"subclass-table" and the 2 subclasses use "new-table" inheritance strategy. 
This maps to 2 tables in the datastore

CREATE TABLE fulltimeemployees
(
    DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY,
    ...
)

CREATE TABLE parttimeemployees
(
    DATASTORE_IDENTITY INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY,
    ...
)

OK, so what's the problem ?

Well, the problem is that "identity" strategy has been specifed in the ORM 
file for both of these subclasses (and the DATASTORE_IDENTITY column is 
IDENTITY too). This means that when we persist a FullTimeEmployee, an object 
is inserted into "fulltimeemployees" and could be given id 1 (by the 
datastore, since it is effectively managing "identity" strategy), and when we 
insert a PartTimeEmployee, an object is inserted into "parttimeemployees" and 
this could also be given id 1 (since the datastore manages that tables ids 
too) !!! The "IDENTITY" keyword is managing ids for that RDBMS table only.
This would break many things. If I call getObjectById() passing in Employee, 
and id value of 1 it wouldn't know which subclass it should use if we have DB 
entries for a FullTimeEmployee (1) and a PartTimeEmployee (1).

Is the JDO impl supposed to guarantee uniqueness of ids in this situation ? 
How ? For the case of the TCK it could be changed to "increment" strategy 
maybe and then the JDO impl could manage these values itself perhaps. In the 
real world the JDO impl could throw an exception in this situation (where 
there is no "base" table that is effectively used to provide uniqueness of 
ids in the inheritance tree)

Comments ?

-- 
Andy

Mime
View raw message