I have an POJO class for a JSON as follows:
public class Portcall {
private Long id;
.
.
PreviousPortCall previousPortCall;
NextPortCall nextPortCall;
.
}
Here all the 3 classes-PortCall, PreviousPortCall, NextPortCall are annotated with @Document. Any change in PortCall.java will have effect on its immediate previous and next object as well which are referred by PreviousPortCall and NextPortCall In case I update the PortCall.java in Mongo DB, which order do I save the objects? Shall I save PreviousPortCall and NextPortCall and then go for saving PortCall.java or vice versa and why?
When you save an object of
Portcall, the complete state of the object is stored into the database. So if your fieldspreviousPortCallandnextPortCallare defined as@Entityas well, they will be stored automatically as the are part of the state of thePortcallinstance. You don't need to save them explicitly at all.Secondly: As long as you store multiple objects within the same
Transaction, the order of storing does not matter, as the complete state will be atomicly visible in the database when the transaction is committed.