What should I prefer when updating the database? What are the pros & cons with either method and when shall I use the one or the other?
public void disem
I think the missing part is, flush() just add to the datasources to be ready to commit, gives actual ids but not persist by default.
So if you need flush() to work as commit() you need to set the flush mode to Commit in the EntityManager by:
void setFlushMode(FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context.
Note that FlushModeType is an enum that has these two values:
FlushModeType AUTO (Default) Flushing to occur at query execution. Since: JPA 1.0 FlushModeType COMMIT Flushing to occur at transaction commit. The provider may flush at other times, but is not required to. Since: JPA 1.0
I hope this help