views:

101

answers:

1

I have two entities that have a many-to-many relationship; they are mapped with annotations @ManyToMany and @JoinTable. In the database join table I also have "order" column which would indicate in which order B entities are listed in A. (The ordering of Bs is specific for each A).

How can I get Hibernate to order list according to the "order" column, when I have List< B > in A, (I'm not interested ordering in the other direction).

A: 

I could do this with @IndexColumn annotation, though it gave me a headache to get everything to work because with that composition key was (A_id, index) and if I tried to change the order directly removing list elements, it would yield problems.

I had to do raw sql that handled ordering with the join table. Phew.

egaga
why not use a set or bag and specify the order by attribute?
bertolami

related questions