@OrderColumn in JPQL query
I have a mapping from @ManyToMany to @OrderColumn like this:
class Tag {
@ManyToMany(fetch = FetchType.LAZY) @Getter
@JoinTable(
name = "tag_graph",
inverseJoinColumns = @JoinColumn(name = "parent_id"))
private Set<Tag> parents = new TreeSet<>();
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "parents") @Getter @OrderColumn
private List<Tag> children = new ArrayList<>();
}
My problem is, I want to write a JPQL query that will use the @OrderColumn generated by @JoinTable. Something like:
SELECT t FROM Tag t WHERE ... ORDER BY t.ORDER_COLUMN
Is there a way to do this?
+3
Vojtěch
source
to share
2 answers
You should be able to use the INDEX function in JPQL.
See, http://en.wikibooks.org/wiki/Java_Persistence/JPQL#Special_Operators
+4
James
source
to share
There is no need to specify the order column in queries, it is automatically used behind the scenes to preserve the order in which the items were added to the relationship list. For a better explanation, you can refer to this link .
-1
remigio
source
to share