How to dynamically order many-to-many relationship with JPA or HQl?
- by Indrek
I have a mapping like this:
@ManyToMany(cascade = CascadeType.PERSIST)
@JoinTable(
name="product_product_catalog",
joinColumns={@JoinColumn(name="product_catalog", referencedColumnName="product_catalog")},
inverseJoinColumns={@JoinColumn(name="product", referencedColumnName="product")})
public List<Product> products = new ArrayList<Product>();
I can fetch the products for the catalog nicely, but I can't (dynamically) order the products.
How could I order them?
I probably have to write a many-to-many HQL query with the order-by clause? I though of passing the orderBy field name string to the query, or is there a better solution?
Tables are:
products,
product_catalog,
product_product_catalog (associative table)
P.S. Using Play! Framework JPASupport for my entities.