title: Manipulating join table row ordering using Hibernate annotations
body: <p>I've done something similar to this with hbm files but so far I haven't found an equivalent using annotations.  What I'd like to be able to do is create an association across a join table where the join table contains an order column for the association (sorry for any incorrect terminology here).  At the very simplest, the tables might look like this:</p>
  
  <pre><code>Table: Menus
  -----
  menu_id
  
  Table: Items
  -----
  item_id
  
  Table: Menus_Items
  ----
  menu_id
  item_id
  order_by
  </code></pre>
  
  <p>If I didn't require that menu items be ordered (this the order_by column) I could do this with no problem; however, I'd like to be able to programmatically order items in the Menus_Items table either in unit tests or in an admin tool.  So for that, I think, I'll also need a MenuItems class, correct?</p>
  
  <p>My question is, what annotations are needed on the corresponding classes to make this happen?
  The classes might look something like this (this is as far as I've got):</p>
  
  <pre><code>public class Menu {
      private List&lt;MenuItem&gt; items;
  
      // ...
  
      @OneToMany
      @JoinTable(name = "Menus_Items", 
          joinColumns = @JoinColumn(name = "menu_id"), 
          inverseJoinColumns = @JoinColumn(name = "item_id"))
      @Cascade(value = { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
      @IndexColumn(name = "order_by")
      public List&lt;MenuItem&gt; getItems() { // ...
      }
  
  }   // end class Menu
  </code></pre>
  
  <p>Is @IndexColumn correct?  Programmatically, how do I specify the order of the MenuItems collection?  What might I be doing wrong?  I have a nagging feeling that I'm missing something obvious.</p>
  
  <p>Any help much appreciated.</p>