Sync entitymanager from database

I have a swing desktop application that uses an entitymanagerfactory, but when that application is executed many times at the same time, the managers of different domains have old data that has been modified by others and these changes will not be visible until the next entitymanagerfactory. .. how can I synchronize entitymanager with database data anytime?

+2


source to share


1 answer


EntityManager

copies should not be stored for long periods of time; instead, each must be used for a unit of work and then discarded.

However, it EntityManager

has a refresh()

method that you can call to reload a specific state from the database.



It also has a method clear()

that completely cleans up "old" data from the persistence context. You have to be careful with this though - calling clear()

without flush()

will cancel any pending updates.

+2


source







All Articles