title: JPA - Adding and Removing elements in List with ElementCollection
body: <p>I keep a list of Strings in SQL as @ElementCollection, my main usage is similar to a Queue:</p>
  <ol>
  <li>fetch it from the database</li>
  <li>run some calculations</li>
  <li>remove the first element and insert a new element to the end of the list:</li>
  </ol>
  <p><code>this.measurements.remove(0); this.measurements.add(measurement);</code></p>
  <ol start="4">
  <li>save it to the database</li>
  </ol>
  <p>The problem with the current implementation is that removing the first element updates the index of all elements in the list (items_order column) which is very bad for performance...
  Is there any other way to do this? perhaps is it possible to have a running index (items_order column) so order will be kept but not position in list?</p>
  <blockquote>
  <p>Example:<br />
  left to ':' is the index of the element and to the right is the element itself.<br />
  [0:&quot;a&quot;, 1:&quot;b&quot;, 2:&quot;c&quot;]</p>
  </blockquote>
  <p>After Calculation the following will be inserted to the database:</p>
  <blockquote>
  <p>[0:&quot;b&quot;, 1:&quot;c&quot;, 2:&quot;d&quot;] - all element indexes have been updated (bad performance)</p>
  </blockquote>
  <p>Possible solution which i'm not sure if possible to implement:</p>
  <blockquote>
  <p>[1:&quot;b&quot;, 2:&quot;c&quot;, 3:&quot;d&quot;] - all elements keep the same order id (still ordered)</p>
  </blockquote>
  <blockquote>
  <p>My entity:</p>
  </blockquote>
  <pre><code>@Entity
  public class Store {
    @ElementCollection
    @OrderColumn
    private List&lt;String&gt; items;
  
    // setter getter
  }
  </code></pre>