Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Second level cache lifespan?

If you do not mind using non-standard API, the session name can be useful. The EntityManagerFactory will front a ServerSession that is named based on the session name. (The server session holds the 2nd level cache.) EclipseLink has a SessionManager that can be used to access sessions. Something like:

SessionManager.getManager().getSession(<name>)

Once you have the session, you can call something like:

session.getIdentityMapAccessor().initializeAllIdentityMaps()

-Tom

On 21/08/2012 1:24 PM, Laird Nelson wrote:
On Tue, Aug 21, 2012 at 7:04 AM, Tom Ware <tom.ware@xxxxxxxxxx
<mailto:tom.ware@xxxxxxxxxx>> wrote:

       Note that JPA 2.0 provides an explicit way to clear the cache -
    emf.getCache().evictAll().


An excellent point, but one that proves a little tricky when EJB enters the picture.

Suppose I'm testing an ejb-jar that makes use of a single persistence unit (call
it X).  My integration harness deploys it, and runs its tests.  In between each
test I want to clear the cache in effect for X.

To do so, I need to have an EJB that is NOT part of the ejb-jar under test
somehow get a handle on an EntityManagerFactory that is nevertheless the one
that was created for the persistence unit under test (X).  Once I have that,
obviously I can clear X's cache.

So from ejb archive Y I need to get a handle on X's persistence unit in such a
way that when I say entityManagerFactory.getCache(), I'm getting X's cache, not Y's.

That was why I was interested in the session name.  Maybe that's still barking
up the wrong tree?

Best,
Laird

--
http://about.me/lairdnelson



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top