First Level Cache in EntityManager [message #533488] |
Fri, 14 May 2010 04:53  |
Eclipse User |
|
|
|
Hi,
I have an application which injects EntityManager in a Stateless Session Bean
@Stateless(mappedName="MySBean")
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class MySBean implements MySBeanRemote, MySBeanLocal {
@PersistenceContext(unitName="MyPU")
private EntityManager em;
.
.
.
The transaction demarcation is Container Managed so I dot not explicitly use em.getTransaction().begin() or em.getTransaction().commit().
I am not sure whether each new instance of the Session Bean will lead to a new instance of the EntityManager and how this will affect the First Level Cache.
For instance :
SLSB Instance 1 creates an EntityManager Instance and creates Object 1. Now Object 1 is in First Level Cache of
Entity Manager and stored in DB.
SLSB Instance 2 creates another EntityManager Instance and
deletes Object 1.
If SLSB Instance 1 attempt to read Object 1 it will propably
return it as it is stored in its First Level Cache although Object 1 does not exist any more in Database.
Is this assumption correct? How will First Level Cache
behave under this scenario?
Thank you in advance,
Petros
|
|
|
Re: First Level Cache in EntityManager [message #533595 is a reply to message #533488] |
Fri, 14 May 2010 12:35  |
Eclipse User |
|
|
|
Since SLSB2 can see the object, it means that SLSB1 has commited its transaction, and so likely has cleared its EntityManager persistence context. After SLSB2 commits, that were pushed to the database will also be merged into the shared cache, so SLSB1 will not find object 1 through queries.
Best Regards,
Chris
|
|
|
Powered by
FUDForum. Page generated in 0.28060 seconds