How to rollback from one-to-many insert

I have one-to-many relationship model:

Invoice which have many of InvoiceDetail.

At first i want to submit invoice and all of its child (InvoiceDetail) at once, but i google it and everyone said it is not possible.

Then i use this approach: Save the invoice, after that loop the invoicedetail and save it.

But there is a problem. In InvoiceDetail Api, there is validation. If qty of product in invoicedetail exceed available qty, the server will return error.

Actual qty always checked when invoicedetail is posted.

When i face this situation, how can i rollback the already saved parent data (invoice)?