Hi!
We are running JBoss with Hibernate and are having this issue.
When a session bean uses an EntityManager to find an entity, it may already exist in the EntityManager's cache and it's state may be already outdated. If the code uses such an entity to make decisions, it may make wrong decisions that would produce bugs.
Here is an example case.
HTTP request 1. A session bean creates an entity instance and stores it with field "A" set to value 1. The persisted entity gets ID = 4.
HTTP request 2. A session bean looks up an entity with ID = 4, sets its field "A" to value 2 and saves it.
HTTP request 3. A session bean looks up an entity with ID = 4 and checks it's field "A". If the value is 1 it does one thing, if it is 2 it does another thing.
In case if the EM in request 3 happens to be the same as in request 1, an undesired behavior occurs. I have tested this and got approx. 10% cases of failure.
So the question is - how to avoid this? Calling em.refresh() or em.clear() each time I have to ensure the entity is up to date seems to be a waste of resources.