I have two entities called owner and pet and its One-to-One mapping unidirectional
Using transaction to perform persist operation. When there are any Issues while saving owner entity, I assumed pet entity should not persist and rollback. But in real scenario pet entity getting persisted. I tried to off auto commit in mysql and tried but that didn’t worked. there should not be any pet with out owner.
How are you persisting these entities? You should use a single transaction where you persist both the owner and the pet, so that if an error occurs at any point the entire transaction will be rolled back. Read more about transactions in our user guide.