Spring JPA: Should the Save() method commit data to the database? Spring JPA: Should the Save() method commit data to the database? spring spring

Spring JPA: Should the Save() method commit data to the database?


When your application runs, the Entity Manager associated with the thread keeps control of modified or added objects, the save() method just do this, it's a mark that says: "this should be saved in the database".

The database DML (insert,update,delete) is not sent to the database while you save things, it's done at the end just before commit, it's delayed to the last moment.

It's possible the send the DML to the database anytime you like using the Entity Manager's flush() method, in fact you can debug the database log and see your queries going through, but this changes to the database will only be visible within your DB connection until the commit is issued; commit() is a method of the transaction associated to the Entity Manager.

In some frameworks like play 1.4.x the commits is issued after the response view is correctly parsed and rendered.