I have entity Order witch has @OneToOne relation to second entity File, relation has orphanRemoval attribute set to true.
Now on postRrmove event, fired after removal of File entity I’m deleting related file form filesystem, on postPersist event I move uploaded file to destination location.
I’m wondering, when updating Order entity with new instance of File entity, what is an order of firing postPersist and postRemove events (in orphanRemoval context)?
Because if postPersist is fired first, nad new File instance has same filename as old one, the uploaded file will override old one, and postRemove event will delete it. Witch is unwanted 🙂
I figured it out, the first event fired is
postPersistof new entity, and thenpostRemoveof old entity.