Question

I wrote an application that uses JPA (and hibernate as persistence provider). It works on a database with several tables.

I need to create an "offline mode", where a copy of the programa, which acts as a client, allows the same functionality while keeping their data synchronized with the server when it is reachable.

The aim is to get a client that you can "detach" from the server, make changes on the data and then merge changes back. A bit like a revision control system.

It is not important to manage conflicts, in case the user will decide which version to keep.

My idea, but it can't work, was to assign to each row in the database the last edit timestamp. The client initially download a copy of the entire database and also records a second timestamp when it modify a row while non connected to the server. In this way, it knows what data has changed and the last timestamp where it is synchronized with the server. When you reconnect to the server, he will have to ask what are the data that have been changed since the last synchronization from the server and sends the data it has changed. (a bit simplified, but the management of conflicts should not be a big problem)

This, of course, does not work in case of deleting a row. If both the server or the client deletes a row they will not notice it and the other will never know.

The solution would be to maintain a table with the list of deleted rows, but it seems too expensive.

Does anyone know a method that works? there is already something similar?

Was it helpful?

Solution

Enver:

If you like to have a simple solution, you can create Version-Fields that acts like your "Timestamp".

Audit:

If you like to have a complex, powerfull solution, you should use the Hibernateplugin

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