users@glassfish.java.net

Re: Clear toplink cache from command line

From: Loren Cole <loren.cole_at_gmail.com>
Date: Mon, 12 Jul 2010 11:41:24 -0500

Gerald,

Thanks for the summary, we've been meaning to move to eclipselink
anyway. Thing is, setting timeouts doesn't really fit our needs. I
want to expire the cache on demand, because sometimes it's weeks
between updates, sometimes days. Having the option to automate it is
nice, but it isn't optimal.

I did actually find a way to do this, using just toplink essentials:

    public void clearCache() {
        ((oracle.toplink.essentials.ejb.cmp3.EntityManager)em.getDelegate()).getServerSession().getIdentityMapAccessor().invalidateAll();
    }

Turns out getDelegate() returns an instance of the EnityManager
(instead of the EntityManagerWrapper that you get through injection).
It's typed as an object and there is some discussion about this being
a bug - but it does allow us to get our hands on the session.

--
Loren
On Fri, Jul 9, 2010 at 6:42 PM,  <glassfish_at_javadesktop.org> wrote:
> It's not Glassfish that's caching - it's Toplink.  The caching behaviour improves performance but is not suitable for your needs.  There are three options to fix your situation-
>
> 1. add the toplink.cache.shared.default property to your persistence.xml to disable the second level cache:
>
> <persistence-unit name="blah" transaction-type="JTA">
>        <properties>
>            <!-- disable ALL caching -->
>            <property name="toplink.cache.shared.default" value="false"/>
>        </properties>
>
> All hits will now go to the database during each client session.
>
> 2. change to Eclipselink and configure caching timeouts (much better and easier to do - highly recommended)
>
> 3. use Hibernate and configure caching through ehcache (more complicated but still good)
>
> We had the problem you described and fixed using (1).  Since then we have moved to Eclipselink 2 and found it to be a *much* nicer solution (Eclipselink is actually Toplink donated to the Eclipse foundation).
>
> Hope this helps
>
> Gerald
> [Message sent by forum member 'ggierer']
>
> http://forums.java.net/jive/thread.jspa?messageID=477240
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>