Suppose I have this classes, notice that entities are not related in anyway.
@Entity
class Laptop {
@Id
String userId;
@Column
String name;
...
}
@Entity
class Foo {
...
@Column
@ElementCollection
List<String> idsPointingToAnEntity;
...
}
Given that I have this Foo
class which has an attribute of idsPointingToAnEntity
, I could store there a list of Laptop ids or any ids of String. Let's say Foo
has idsPointingToAnEntity=[1,2,3], this [1,2,3] has an equivalent Laptop entry in the database.
How can I left join/ join them with ordering in JPQL such given that the result is a list of Foo sorted by Laptop names.
In theory I think it is something like this.
Select f From Foo f LEFT JOIN Laptop l ON l.id IN f.idsPoitingToAnEntity ORDER by l.name
But this is having an error for me since f.idsPoitingToAnEntity
is a Join table.
Note: idsPointingToAnEntity
can also be another entity making List<Laptop>
is not an option