views:

103

answers:

1

Hi. i have a swing desktop application that use a entitymanagerfactory, but when this application is executed many times at the same time, the diferents entity managers have old data that was modified by others and this changes will not visible until the next entitymanagerfactory... how can i sync in anytime the entitymanager with the database data??

A: 

EntityManager instances should not be held for prolonged periods of time; instead each should be used for unit of work and discarded afterwards.

That said, EntityManager has a refresh() method you can invoke to reload state of a particular entity from the database.

It also has a clear() method which will clear the persistence context completely of "old" data. You need to be careful with it, though - calling clear() without flush() will discard all pending updates.

ChssPly76