title: Can Hibernate automatically manage the order of child collections?
body: <p>Given a <code>Parent</code> class which has many <code>Children</code>, can Hibernate automatically manage the order of said children? From reading documentation and searching, it seems that the <code>@OrderColumn</code> annotation may enable this, but I've not found any examples of how to do it. The closest thing I've found is <a href="https://stackoverflow.com/questions/2956171/jpa-2-0-ordercolumn-annotation-in-hibernate-3-5">JPA 2.0 @OrderColumn annotation in Hibernate 3.5</a>, which looks a bit discouraging, given that it looks just like what I want to do.</p>
  
  <p>Here is a rough sketch of what I'm trying to do, minus the annotations, since I'm not sure what they would be:</p>
  
  <pre><code>class Parent {
    // I probably need some sort of @OrderColumn annotation here, right?
    private List&lt;Child&gt; children = new ArrayList&lt;Child&gt;;
  }
  
  class Child {
    private Parent parent;
    private int order;
  }
  
  class SomeBusinessLogic {
    public static void createFamily() {
      Parent dad = new Parent("Tom");
      List&lt;Children&gt; children = dad.getChildren();
      children.add(new Child("Alice");
      children.add(new Child("Bob");
      children.add(new Child("Carl");
      session.save(dad);
    }
  
    public static void addChild(Parent parent) {  // assuming Tom is passed in
      List&lt;Children&gt; children = parent.getChildren();
      children.add(1, new Child("Zelda");
      session.save(parent);
      // now, the order should be: Alice, Zelda, Bob, Carl
    }
  }
  </code></pre>
  
  <p>If someone can give me enough details to make this toy example work (or tell me that it will not work), I would be most appreciative.</p>