Unfortunately, OpenJPA does not have the support for generics as you are
attempting to use them, as documented by this append earlier this year [1].
Of course, we support generics as defined by the spec so that the target
entity type does not have to be specified for collection-based
relationships.  But, extending that generics support to MappedSuperClasses
and Entities has not been done yet.

We are always welcome to new contributors.  As referenced in the append
below, this work effort is not trivial.  It's definitely doable, but it will
take some effort.

Thanks,
Kevin

[1]
http://openjpa.208410.n2.nabble.com/Generics-Support-tp5049201p5049201.html

On Wed, Jan 26, 2011 at 11:24 AM, agurkas <[email protected]> wrote:

>
> Hi guys,
>
> I must be missing something simple to get generics working with openjpa:
>
> this is a very simple example.
>
> @MappedSuperclass
> public class Fruit {}
>
> @Entity
> public class Apple extends Fruit {}
>
> @Entity
> public class Orange extends Fruit {}
>
> @MappedSuperclass
> public class Tree<T extends Fruit> {
>
> @ManyToOne (cascade = CascadeType.ALL) // targetEntity ?
> @JoinColumn
> private T fruit;
>
> //getters setters
>
> }
>
> @Entity
> public class AppleTree extends Tree<Apple> {}
>
> @Entity
> public class OrangeTree extends Tree<Orange> {}
>
>
> @Test
> Apple fruit = new AppleFruit();
> AppleTree tree = new AppleTree();
> tree.setFruit(fruit);
> //save  tree
> //after saving we should be able to retrieve AppleTree with Apple fruit
>
> openjpa seems cannot guess targetEntity on @ManyToOne
>
> what is way to get it working?
>
> Out of despair I even tried using @ManyToOne with targetEntity specified on
> subclasses (declaring on a method not a field level) does not work either.
> (And I don't like this approach).
>
> Help is greatly appreciated.
>
> Agurkas
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/very-simple-generics-example-but-how-to-make-it-work-with-openjpa-tp5963498p5963498.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to