@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
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
source to share