openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Saint Croix" <saintx.opensou...@gmail.com>
Subject Pinaki's blog entry on persisting a generic fields using @Type annotations
Date Sun, 13 Jan 2008 02:04:51 GMT
Pinaki,

Before anything else, I'm very sorry about the typo in your name in my last
post.  :-(

I pulled down the source for OpenJPA and dug through looking for the
@interface Type, and found it.

The file org.apache.openjpa.persistence.Type in the defines the annotation
@interface that was seen in Pinaki's blog about generic persistence in
OpenJPA.  Specifically this part:

@Entity
> @DataStoreId
> public class Edge<T> implements Serializable {
>   @OneToOne
>   @Type(Entity.class)
>   private T source;
>
>   @OneToOne
>   @Type(Entity.class)
>   private T target;
>
>   @PersistentMap
>   private Map<String,String> attributes;
>

Although @Type is not a spec-compliant annotation, the ability to persist
generic field types is utterly irresistable, and I'm willing to make OpenJPA
the only persistence provider for my project in the short to medium term.

The reason is pretty simple.  I _originally_ implemented these classes to
use generics, then had to back out of those APIs when I sat down to try to
persist everything.  OpenJPA lets me actually write my code the way I
originally intended, and so, far from being a sort of lock-in nuisance, it's
very liberating.  (I'd still like to see generic field persistence in future
versions of the JPA spec!)

This is such a promising feature.  My app will benefit immensely from the
ability to persist generic fields, so I thank you. (Now I just need to get
the proof-of-concept persisting!)

Hope you have a pleasant weekend, sir.

Best regards,
--
Alexander R. Saint Croix












On Jan 12, 2008 6:07 PM, Alexander Saint Croix <saintx.opensource@gmail.com>
wrote:
> Panaki,
>
> I read your blog entry on persisting a generic graph and am very
interested in using something similar to this for some of my entities.
>
> The pattern I'm looking to do is something like the following:
>
>
> > @MappedSuperclass
> > public abstract class Foo implements Serializable {
> >     @Id
> >     private long id;
> >
> >     public long getId() { return id; }
> >     public void setId(long id) { this.id = id; }
> >
> >     public void doStuff() {
> >         // stuff.  very abstract, to be sure.
> >     }
> > }
> >
> > @Entity
> > public class ConcreteFoo extends Foo {
> >     public void doConcreteStuff() {
> >         // more concrete stuff
> >     }
> > }
> >
> > @Entity
> > public class OtherFoo extends Foo {
> >     public void doOtherStuff() {
> >         // more concrete stuff
> >     }
> > }
> >
> > @Entity
> > public class Funk<F extends Foo> {
> >     private F foo;
> >
> >     public F getFoo() { return foo; }
> >
> >     public void setFoo(F foo) { this.foo = foo; }
> > }
> >
>
> The idea would be to allow client code to create "new Funk<ConcreteFoo>()"
and work with the class in a simpler fashion.  (think Foo == Party,
ConcreteFoo == Person, OtherFoo == Organization and Funk ==
PartyRelationship for more of a sense what I'm going for here.)
>
> Does this make sense and is it possible?  In your blog entry you mention
the @Type annotation.  Can't find references to it anywhere so thought I'd
ask the expert.
>
> Cheers!
> --
> Alexander R. Saint Croix
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message