You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Erik Bengtson <er...@jpox.org> on 2007/01/20 12:51:14 UTC

Re: Questions regarding persistent interfaces

I have some questions regarding persistent interfaces.

1) If a class implements (in the Java sense via the 'implements'
clause), an interface that is declared persistent-capable in the
metadata, does the corresponding <class> element in the metadata also
required to have a corresponding <implements> element or is the element
implied by the Java structure? I think one would expect this but the
spec doesn't say explicitly.

The Implements attribute allows in declarative form to the JDO implementation
know all the types that implement a certain interface used in a field of a
persistent class. e.g.

Class Person
{
    Thing thing; //persistent field
}

Interface Thing {} //non persistent interface

Class Stuff implements Thing {} //persistent
Class Misc implements Thing {} //persistent

With the implements metadata, the JDO implementation is capable to search for
all Thing kinds, + create the database schema

For example one could have a schema:

PERSON_TABLE
THING_COL (FK)

THING_TABLE
THING_ID
CLASS_NAME (STUFF,MISC)

Another model could be:

PERSON_TABLE
THING_STUFF_COL (FK)
THING_MISC_COL (FK)

STUFF_TABLE
STUFF_ID

MISC_TABLE
MISC_ID

Hopefully Implements is clear now.

Persistent interfaces are used only when you want the JDO implementation to
provide the concrete implementation for you.

You could also have Mixed mode, when you have implementations of Persistent
Interfaces created by the JDO implementation, but also implementations provided
by the user. This has been discussed before, and some of the TCK tests covers
this indirectly.

2) If a class implements a persistent-capable interface, is there a
default mapping between the interface properties and class field names
(i.e. would a property named "modDate" of type java.util.Date map by
default to a field in the implementing class of the same name and type?
If not, why not?

Not to field names, but to getters and setters.

3) Based on the spec, I guessing the answer to this is no but given a
persistent-capable interface, is there a way to specify that
implementation generated instances (i.e. pm.newInstance(interfaceName))
should not be allowed?

You simply do not declare the interface as persistence capable, and for each
implementation of your interface, declare the jdo metadata with the implements
element.