Question

I have a question about persist and merge strategy of eclipselink. I would like to know how eclipselink/JPA inserts and updates records. Is it insert/update one by one into database? or it is saving them in a log file and then flush them to the database? It is important for me, because I am going to have a history table with trigger that triggs when insertion and update. so if for example update is happening on each field, and 3 fields are updated, then I will have 3 records in history table or one? I will be appreciated if anyone answers me and also leave some reference link for further information.

Was it helpful?

Solution

The persistence provider is quite free to flush changes whenever it sees fit. So you cannot reliably predict the number of update callbacks or the expected SQL statements.

In general, the provider will flush changes before each query to make changes in the persistence context available to the query. You can hint the provider to defer the flush until commit time, but the provider still can flush at will.

Please see the relevant chapters of the JPA (2.0) spec:

  • §3.2.4 Synchronization to the Database
  • §3.8.7 Queries and Flush Mode

EDIT: There is an important point to flushing and transaction isolation. The changes are flushed to the database and the lifecycle listeners are invoked, but the data is not committed and not visible to other transactions - the read-committed isolation is the default. The commit itself is atomic.

I am not sure what the consequences of a server crash would be, but under normal circumstances, data integrity is ensured.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top