Skip to content

JpaSort.path results in ambiguous method with PluralAttributes [DATAJPA-1795] #2089

Open
@spring-projects-issues

Description

@spring-projects-issues

feliperuiz opened DATAJPA-1795 and commented

The setup

I have a many-to-many relationship between entities E1 and E2 going through an association entity E3, which contains additional attributes. A very rough sketch of that setup looks like the following, with irrelevant parts like primary keys and the like omitted for brevity:

@Entity
public class E1 {
    Set<E3> associations;
}

@Entity
public class E2 {
    Set<E3> associations;
}

@Entity
public class E3 {
    String attr1;
    BigDecimal attr2;
}

 

The metamodel ends up looking like this:

public class E1_ {
    public static volatile SetAttribute<E1, E3> associations;
}
public class B_ {
    public static volatile SetAttribute<E2, E3> associations;
}
public class C_ {
    public static volatile SingularAttribute<E3, String> attr1;
    public static volatile SingularAttribute<E3, BigDecimal> attr2;
}

The issue

With that setup, the issue lies when trying to query for E1 while sorting by an attribute of E3, like in the example below, which results in an ambiguous method call:

JpaSort.path(A_.associations).dot(C_.attr2)

 

Given JpaSort.path has two signatures—one where the formal parameter extends Attribute<T, S> and another where it extends PluralAttribute<T, ?, S>—and SetAttribute<E1, E3> extends PluralAttribute<E1, Set<E3>, E3>—which itself extends Attribute<E1, Set<E3>>—the compiler doesn't know if it should match PluralAttribute<E1, E3> or Attribute<E1, Set<E3>> and no amount of type casting I employed could solve this ambiguity


No further details from DATAJPA-1795

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions