You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Alexander Saint Croix <sa...@gmail.com> on 2007/12/13 22:45:32 UTC

Question about MappedSuperclass

Howdy,

I'm working on a very large (100+ entities) component hierarchy in which
nearly every class has a "name" and "description" field of type String.   I
decided early on to create an abstract base class called "Archetype" that
defines only these two fields, along with accessors and mutators.  Now
nearly every class in my component library extends this abstract Archetype
base class.

At the moment, I'm working on the persistence mappings for a subclass of
Archetype called Party.  Party has its own unique ID field "id", and a
number of other properties.

My question is this: Must my abstract superclass possess a primary key
field?  I do not intend for Archetype itself ever to be instantiated.  I
_believe_ I should annotate it with MappedSuperclass.  Is this correct,
and/or will this work in OpenJPA?  If not, will it work anywhere?

Not all of my subclasses have their own primary key fields.  Some use
embedded IDs and some use foreign keys, depending on circumstances.  So it
seems unlikely that creating the ID field in the superclass is the correct
way to go about matters.

I read section 2.1.9.2 in the persistence spec, and all of the examples have
primary keys defined, both for the MappedSuperclass and for the abstract
entity classes, though nothing regarding the necessity of primary keys in
Mapped Superclasses is ever explicitly stated (so far as I can see).

Regards,
--
Alexander R. Saint Croix

Re: Question about MappedSuperclass

Posted by Alexander Saint Croix <sa...@gmail.com>.
SuperToll.

Thanks, Daniel
--
Alex

I don't see why not.  This sounds similar to the approach I am using.  It
> works fine for me.
> --
> Daniel Dyer
> http://www.uncommons.org
>

Re: Question about MappedSuperclass

Posted by Daniel Dyer <da...@dsl.pipex.com>.
On Thu, 13 Dec 2007 21:45:32 -0000, Alexander Saint Croix  
<sa...@gmail.com> wrote:

> My question is this: Must my abstract superclass possess a primary key
> field?  I do not intend for Archetype itself ever to be instantiated.  I
> _believe_ I should annotate it with MappedSuperclass.  Is this correct,
> and/or will this work in OpenJPA?

I don't see why not.  This sounds similar to the approach I am using.  It  
works fine for me.

> Not all of my subclasses have their own primary key fields.  Some use
> embedded IDs and some use foreign keys, depending on circumstances.  So  
> it
> seems unlikely that creating the ID field in the superclass is the  
> correct
> way to go about matters.
>
> I read section 2.1.9.2 in the persistence spec, and all of the examples  
> have
> primary keys defined, both for the MappedSuperclass and for the abstract
> entity classes, though nothing regarding the necessity of primary keys in
> Mapped Superclasses is ever explicitly stated (so far as I can see).

I have abstract mapped super-classes without keys and concrete sub-classes  
with keys.  I haven't noticed any problems.

Dan.

-- 
Daniel Dyer
http://www.uncommons.org