[hibernate-dev] Typing Help with JPA 2.1 impl

Hardy Ferentschik hardy at hibernate.org
Thu Jun 14 05:45:27 EDT 2012


Hi,

OOI, have you tried with the Java 7 compiler? I think there used to be a bug in the Java 6 compiler 
when it came to covariant return types.

--Hardy



On Jun 13, 2012, at 10:04 PM, Steve Ebersole wrote:

> I realize I could split Join and Fetch into different hierarchies.  
> That is what I want to try to avoid though...
> 
> On Wed 13 Jun 2012 02:55:03 PM CDT, Steve Ebersole wrote:
>> I need some help with generic types in the JPA 2.1 API, specifically
>> with regard to the new Join#on and Fetch#on methods. We ultimately
>> unify those 2 interface hierarchies into a single hierarchy in out
>> code using org.hibernate.ejb.criteria.JoinImplementor which extends
>> from both Join and Fetch.
>> 
>> The problem I am facing is in the return types. So, Join defines:
>> public interface Join<Z,X> {
>> public Join<Z,X> on(...);
>> ...
>> }
>> 
>> Fetch defines:
>> public interface Fetch<Z,X> {
>> public Fetch<Z,X> on(...);
>> ...
>> }
>> 
>> 
>> public interface JoinImplementor<Z,X>
>> extends Join<Z,X>, Fetch<Z,X>, FromImplementor<Z,X> {
>> ...
>> }
>> 
>> The compiler does not at all like JoinImplementor as is, so I have to
>> override the method:
>> 
>> public interface JoinImplementor<Z,X>
>> extends Join<Z,X>, Fetch<Z,X>, FromImplementor<Z,X> {
>> public JoinImplementor<Z,X> on(...);
>> ...
>> }
>> 
>> which should be fine as it is simple return type clarification. And
>> actually that definition compiles fine.
>> 
>> However, JPA also defines a whole hierarchy from Join such as.
>> CollectionJoin, ListJoin, etc. So Hibernate has for example:
>> 
>> public interface CollectionJoinImplementor<Z,X> extends
>> JoinImplementor<Z,X>, CollectionJoin<Z,X> {
>> @Override
>> public CollectionJoinImplementor<Z, X> on(...);
>> ...
>> }
>> 
>> The IDE is fine with this type signature, however trying to compile
>> this leads to the following error:
>> 
>> types org.hibernate.ejb.criteria.JoinImplementor<Z,X> and
>> org.hibernate.ejb.criteria.JoinImplementor<Z,X> are incompatible; both
>> define on(javax.persistence.criteria.Predicate[]), but with unrelated
>> return types
>> 
>> I have no idea what I need to do here. Can anyone see the solution?
>> 
>> 
> 
> --
> steve at hibernate.org
> http://hibernate.org
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev




More information about the hibernate-dev mailing list