title: Persisting a temporal collection with JPA
body: <p>I need to persist with JPA a <strong>collection of a collection which changes temporally</strong>.</p>
  
  <p>Suppose I have a <code>Customer</code> making <strong>multiple</strong> <code>Orders</code> at a time, I'd need operations like:</p>
  
  <pre><code>Customer c = new Customer();
  Set&lt;Order&gt; o = new Set&lt;Order&gt;();
  Instant validFrom = now(); // something similar
  Instant validTo = infinity(); // something similar
  c.setOrders(validFrom, validTo, o);
  </code></pre>
  
  <p>with structures like</p>
  
  <pre><code>class TemporalSet&lt;V&gt;  {
  ...
      Instant validFrom;
      Instant validTo;
      Set&lt;V&gt; value;
  }
  </code></pre>
  
  <p>and with Customer being </p>
  
  <pre><code>class Customer {
  
      Collection&lt;TemporalSet&lt;Order&gt;&gt; orders;
  }
  </code></pre>
  
  <p><strong>I need to persist the <code>orders</code> field with JPA</strong>, and I don't know how to do this. </p>
  
  <p>In the past, when I asked how to handle temporal <strong>properties</strong>,  someone suggested me to give a look at the <a href="http://opensource.anasoft.com/daofusion-site/" rel="nofollow noreferrer">DaoFusion framework</a>, which  includes the <a href="https://github.com/klr8/bitemporal" rel="nofollow noreferrer">Bitemporal Pattern by Erwin Vervaet</a>, but as far as I understand, one can use it only to map bitemporal <strong>properties</strong> (not collections), as the mapping is a OneToMany, so the second side must be a single value. </p>
  
  <p>The example shown in the Bitemporal pattern section of DaoFusion shows indeed an example with Customer and Orders which is similar to mine, but as far as I understand one can only have one order at a time, not a collection of orders. </p>
  
  <p>Did I correctly understand that code?</p>
  
  <p>How would one handle a temporal collection with JPA? (I need only valid time, I don't need a bitemporal solution with record time)</p>
  
  <p>edit: the question has been updated adding the fields of Customer and of TemporalSet</p>