openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Curious about subclassing rather than entity enhancement
Date Mon, 27 Jul 2009 17:05:35 GMT
Hi Mike,

On Jul 27, 2009, at 8:45 AM, Yawn, Mike wrote:

>
>
> I'm curious about something I read on the 'Entity Enhancement' page.
> Currently, our "JPA-like" implementation of annotations uses the
> standard JPA annotations, but on an interface rather than a class.

This is a very common (good) pattern for persistence.

> Then, our code generation generates the implementation classes from  
> the
> interface; we don't ever add or modify code behind the user's back, so
> all the implementation code is fully visible.

So you need a factory to allow the user to create a new instance of  
the implementation class. How do you tell the user what to "new", or  
perhaps you have a factory with a method like <T> T  
newInstance(Class<T> interface)?
>
> On the entity enhancement page, there is a statement that "Some JPA
> providers auto-generate new subclasses or proxy objects that front the
> user's Entity objects at runtime" ...., and I'm curious how this works
> given that it seems that the mechanism for creating an entity object  
> is
> to call "new" on it.

This is how users create an entity to persist. But once it's  
persisted, the provider has its own factory that it uses when fetching  
instances from the database.

> So, if there is a JPA-annotated class that
> represents the entity, and then a JPA implementer creates a subclass  
> of
> this to provide loaded / dirty tracking, etc., it seems that any
> instantiation of the Entity via "new"  would be getting the annotated
> base class, not the subclass with the implementation of these  
> features.

Right.

> How is that being handled in JPA implementations that use subclasses
> rather than byte-code weaving ?

Byte-code enhancement is done primarily to allow detection of changes,  
which by definition isn't needed for new instances (all fields are  
considered changed for newly persisted instances).

Craig
>
>
>
>
>
> Thanks,
>
> Mike Yawn
>
> eBay Inc.
>

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message