when you see the problem occur, do the order details records have a blank detailorderid column?
It's very difficult to troubleshoot an issue that only occurs some of the time. if you can come up with steps to reproduce the error, I could start a ticket and we could troubleshoot the problem with you to find the cause, but we would need to be able to faithfully reproduce the issue.