Hi,
I have a problem with mapping a many to many relation to a list.
I have a Many to Many relation in my database between tables baskets and products. This relation is implemented with a join table basket_products, which has two fields which correspond to the foreign keys to tables baskets and products. The join table need to have another one column "order", which defines the order of the products for the specific basket.
In my mapping I have:
@Entity @Table(name = "baskets", uniqueConstraints = {}) public class Components implements java.io.Serializable { @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY) @JoinTable( name="baskets_products", joinColumns=@JoinColumn(name="b_id", referencedColumnName="pr_id"), inverseJoinColumns=@JoinColumn(name="pr_id", referencedColumnName="pr_id")) //This of course doesn't work!! //@OrderBy(value="order") public List<Products> getProductses() { return this.productses; } public void setProductses( List<Products> productses) { this.productses = productses; } @Entity @Table(name = "products", uniqueConstraints = { }) public class Products implements java.io.Serializable { @ManyToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "productses") public Set<Baskets> getBasketses() { return this.basketses; } public void setBasketses(Set<Basket> basketses) { this.basketses = basketses; }
Hi,
I have exactly the same problem.
I want to order a many-to-many association with a field like an index in the join table.
Is there a fix since 2006 ?
tks !