How to dynamically order many-to-many relationship with JPA or HQl?
Posted
by Indrek
on Stack Overflow
See other posts from Stack Overflow
or by Indrek
Published on 2010-06-08T23:37:55Z
Indexed on
2010/06/08
23:52 UTC
Read the original article
Hit count: 185
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.
© Stack Overflow or respective owner