I am creating a billing system which manages a Ledger for each customer. Each Ledger has a list of LedgerEntry's which records each customer transaction.
As I was testing this, I noticed that if I created a bunch of LedgerEntry's within the same transaction, the @Id value was not in order that the objects were given to em.persist(), unless I did a em.flush() after each entry is created.
Because I rely on the order of the id for the proper behavior of the Ledger (specifically, the current balance is the last LedgerEntry in the list -- enforced by a @OrderBy "id ASC"), this means that I have to flush() a bunch of times.
Is there a way to avoid flushing after each row is created? That is, to have some sort of ordering on how the objects are persisted, without using an @OrderColumn?