The link provided by okwap is very useful. To make sure that it does not slip, and to follow the rules of the board, I posted a copy here:
- an EntityManager contains a persistence context, that will track
everything read through it, so to avoid bloated memory, you should
acquire a new one, or clear it at some point
- if you read the same object through two different EntityManager you
will get different objects back, so will loose object identity, which
is something to consider
Based on this, I will add that reading through two different EntityManager can even give objects with different content if the database transaction was performed by someone else in the meantime. But if you read several times through the same noun. The person, the second readable wil, just gets the object from the entitymanager cache, so the new state will simply not be visible.
source share