openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <cefn.ho...@bt.com>
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...

@MappedSuperclass
public class Tree<T extends Fruit> {

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

public Fruit getFruit(){
    return fruit;
}

}

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

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



________________________________________
From: agurkas [agurkas.zalias@yahoo.com]
Sent: 26 January 2011 20:09
To: users@openjpa.apache.org
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
cases.

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,

Agurkas



--
View this message in context: http://openjpa.208410.n2.nabble.com/very-simple-generics-example-but-how-to-make-it-work-with-openjpa-tp5963498p5964005.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message