Context: Java EE application should minimize the risk of data loss as much as possible. This can come at the cost of performance for now, as the load on the server is not that high.
My understanding is that GenerationType.IDENTITY
performs an immediate insert operation into the database when the Object is instantiated, whereas GenerationType.SEQUENCE
performs a read operation on the database to retrieve the next value of a database sequence. The source used for this information is from here. Please correct me if my understanding is wrong.
Given my understanding, should GenerationType.IDENTITY
be preferred over GenerationType.SEQUENCE
in this context since data is persisted to the database earlier?