Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are using the same EntityManager instance. The cache settings apply to the shared cache, while the EntityManager is required to keep the same object in memory until it is closed or cleared - otherwise a simple find operation might wipe out changes in a running transaction. Get a new EntityManager or clear the existing one will cause the EntityManager to go to the shared cache and/or the database as necessary. </p> <p>If you do need the object refreshed in the current EM context, you will have to explicitly call em.refresh or use a query hint so that it knows to wipe out any existing changes with what is in the database. </p> <p>Each EM represents a transactional context, and since each thread should have its own EntityManager, there will already be multiple copies of your entity in the application. You will run into trouble if you rely on a particular instance read from an EntityManager always reflecting the current changes - it can only really reflect what is in the database at the moment it was read. This is why it is important to merge in changes when necessary, and is probably not a good idea to cache objects in the application - access them from EntityManagers as needed instead. </p> <p>ut if you want the object and are not making changes, mark it as read-only which will pull it from the shared cache instead of the EM, and so reflect the cache settings: <a href="http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Shared_and_Isolated#Read-Only_Entities" rel="nofollow">http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Caching/Shared_and_Isolated#Read-Only_Entities</a> . If the entity is cached in the shared cache, this will be the instance you get back, and all EMs will return the same object instance - it is up to your app to manage concurrency issues on the entity itself.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload