Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » First Level Cache in EntityManager(How first level cache behaves when EntityManager is injected in SLSB)
First Level Cache in EntityManager [message #533488] Fri, 14 May 2010 08:53 Go to next message
Petros Petrou is currently offline Petros PetrouFriend
Messages: 4
Registered: May 2010
Junior Member
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 16:35 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
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
Previous Topic:entity.getAlist() reopen de emFactory and entityManager that was previously closed!!
Next Topic:Prevent errors in log when using drop-and-create-tables for eclipselink.ddl-generation
Goto Forum:
  


Current Time: Tue Apr 16 10:56:16 GMT 2024

Powered by FUDForum. Page generated in 0.12928 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top