title: JPA: Can I force objects to be persisted to the database in the order that the objects were sent to persist()?
body: <p><a href="https://stackoverflow.com/questions/3747780/jpa-how-can-i-">I am creating a billing system</a> which manages a Ledger for each customer.  Each Ledger has a list of LedgerEntry's which records each customer transaction.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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?</p>