You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Temujin_12 <ju...@yahoo.com> on 2009/11/24 17:35:34 UTC

Behavioral Inheritance

I'm trying to figure out how to use inheritance with OpenJPA, however the
documentation I've read on inheritance describes it being used in a way that
is different from how I'm trying to use it.

In my database several tables have "audit_*" columns to track
creation/modification/author values for rows. What I'd like to do is create
an Auditable interface along with an OpenJPA-annotated abstract class that
maps these "audit_*" columns and provides the getters/setters along with
other audit-specific methods so that other OpenJPA classes that map to
different tables can just extend this abstract class and not have to
redefine the OpenJPA annotations.

Can this be done?
-- 
View this message in context: http://n2.nabble.com/Behavioral-Inheritance-tp4058975p4058975.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Behavioral Inheritance

Posted by Judes Tumuhairwe <ju...@gmail.com>.
Yes.
In my app, I'm doing exactly this. I have a super class that all entities
extend.

@MappedSuperclass
public abstract class AuditableRecord{} that looks almost exactly like the
ModelBase class here [1]

Basically it has a createDate [timestamp, updateable=false], createUser
[string, updateable=false], and lastUpateDate and lastUpdateUser.

[1] See this for a complete example:
http://www.theserverside.com/tt/articles/article.tss?l=JPAObjectModel

regards,
Judes Tumuhairwe

On Tue, Nov 24, 2009 at 11:35 AM, Temujin_12 <ju...@yahoo.com>wrote:

>
> I'm trying to figure out how to use inheritance with OpenJPA, however the
> documentation I've read on inheritance describes it being used in a way
> that
> is different from how I'm trying to use it.
>
> In my database several tables have "audit_*" columns to track
> creation/modification/author values for rows. What I'd like to do is create
> an Auditable interface along with an OpenJPA-annotated abstract class that
> maps these "audit_*" columns and provides the getters/setters along with
> other audit-specific methods so that other OpenJPA classes that map to
> different tables can just extend this abstract class and not have to
> redefine the OpenJPA annotations.
>
> Can this be done?
> --
> View this message in context:
> http://n2.nabble.com/Behavioral-Inheritance-tp4058975p4058975.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>