openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject RE: very simple generics example, but how to make it work with openjpa?
Date Fri, 28 Jan 2011 00:48:41 GMT
It's not exactly what you were suggesting, but if you want those specific signatures, I'm pretty
sure you can override methods but return subclasses, meaning you can reply on typed references
to AppleTree and OrangeTree to give you the correct types...

public class Tree<T extends Fruit> {

@ManyToOne (cascade = CascadeType.ALL) // targetEntity ?
private Fruit fruit;

public Fruit getFruit(){
    return fruit;


public class AppleTree extends Tree<Apple> {
public Apple getFruit(){
    return Apple.class.cast(super.getFruit());

public class OrangeTree extends Tree<Orange> {
public Orange getFruit(){
    return Orange.class.cast(super.getFruit());

From: agurkas []
Sent: 26 January 2011 20:09
Subject: Re: very simple generics example, but how to make it work with openjpa?

Hi Kevin,

Thank you for your kind reply.
Before posting I did search on generics related questions in this user
forum. I did not realise it was thoroughly discussed in developers forum as
you pointed out.
I am sorry I wasted your time.

I understand it must be not a part of JPA2 spec but full support for generic
types would be an absolutely amazing addition. I am using Openjpa in a large
project and can clearly see it would be useful to simplify code in many

Do you know if this is possible in any other JPA implemetations? From the
forums it seems Eclipselink is working on this. Not sure about Hibernate. I
will check it in more depth when I get time.
It's not that I want to abandon Openjpa. Just out of curiosity.

You guys are doing a great job.

with all respect,


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message