# orphanRemoval: replacing the collection instead of changing it
# Hibernate ORM 7.4.15.Final, H2, JDK 25

== setLines(new ArrayList<>()) on a managed invoice
-- setLines(new ArrayList<>()); flush()
   sql> select i1_0.id,i1_0.number from Invoice i1_0 where i1_0.id=?
   threw: org.hibernate.HibernateException
   cause: A collection with orphan deletion was no longer referenced by the owning entity instance: com.ankurm.cascade.Invoice.lines
raw rows after rollback: InvoiceLine=2

== The safe way: clear() the existing collection
-- getLines().clear(); flush()
   sql> select i1_0.id,i1_0.number from Invoice i1_0 where i1_0.id=?
   sql> select l1_0.invoice_id,l1_0.id,l1_0.description from InvoiceLine l1_0 where l1_0.invoice_id=?
   sql> delete from InvoiceLine where id=?
   sql> delete from InvoiceLine where id=?
raw rows: InvoiceLine=0
