Persisting a temporal collection with JPA

200 views Asked by At

I need to persist with JPA a collection of a collection which changes temporally.

Suppose I have a Customer making multiple Orders at a time, I'd need operations like:

Customer c = new Customer();
Set<Order> o = new Set<Order>();
Instant validFrom = now(); // something similar
Instant validTo = infinity(); // something similar
c.setOrders(validFrom, validTo, o);

with structures like

class TemporalSet<V>  {
...
    Instant validFrom;
    Instant validTo;
    Set<V> value;
}

and with Customer being

class Customer {

    Collection<TemporalSet<Order>> orders;
}

I need to persist the orders field with JPA, and I don't know how to do this.

In the past, when I asked how to handle temporal properties, someone suggested me to give a look at the DaoFusion framework, which includes the Bitemporal Pattern by Erwin Vervaet, but as far as I understand, one can use it only to map bitemporal properties (not collections), as the mapping is a OneToMany, so the second side must be a single value.

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.

Did I correctly understand that code?

How would one handle a temporal collection with JPA? (I need only valid time, I don't need a bitemporal solution with record time)

edit: the question has been updated adding the fields of Customer and of TemporalSet

0

There are 0 answers