title: How to keep list insertion order when saving to db using Spring
body: <p>I'm using spring-boot and I have an Entity class (class A) that contains a list of elements from a different class (class B).</p>
  
  <p>In general, the list contains list of orders, and there is no timestamp.</p>
  
  <p>I want to save an object of class A to MySql DB while keeping the insertion order of the list.
  Is that possible?</p>
  
  <p>Thanks,
  Avi</p>
  
  <pre><code>@Entity
  public class A {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  @ManyToMany(targetEntity = B.class, fetch = FetchType.EAGER)
  private List&lt;B&gt; orders;
  }
  
  @Entity
  public class B {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  private String order;
  }
  </code></pre>