db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Watzek <mwa.t...@spree.de>
Subject Re: Inheritance test schema 2 : "subclass-table" and "identity" strategy
Date Wed, 28 Sep 2005 13:37:22 GMT
Hi Andy,

> 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).
I'm not sure what you mean by "getObjectById() passing in Employee".

The object model specifies that class Employee is abstract. Thus, there 
cannot exist persistent instances of Employee which are not instances of 
  Employee subclasses. This means that there are no object id instances 
of class Employee.

Maybe you mean that two datastore objectid instances, one for 
FullTimeEmployee and the other for PartTimeEmployee, having the same 
value in the database wrt their identity columns (e.g. 1) would equal in 
the object model?

Regards,
Michael
> 
> 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 ?
> 


-- 
-------------------------------------------------------------------
Michael Watzek                  Tech@Spree Engineering GmbH
mailto:mwa.tech@spree.de        Buelowstr. 66
Tel.:  ++49/30/235 520 36       10783 Berlin - Germany
Fax.:  ++49/30/217 520 12       http://www.spree.de/
-------------------------------------------------------------------

Mime
View raw message