users@glassfish.java.net

Re: Cleaning out EclipseLink cache between EJBs

From: Phillip Ross <phillip.w.g.ross_at_gmail.com>
Date: Fri, 2 Dec 2011 10:53:17 -0500

This may illustrate better:

@BeforeSuite
    public void startupContainer() {
        URL url =
Thread.currentThread().getContextClassLoader().getResource("test-domain.xml");
        String configFileName = url.getFile();
        Map<String, Object> ejbContainerProperties = new
HashMap<String, Object>();
        ejbContainerProperties.put("org.glassfish.ejb.embedded.glassfish.configuration.file",
configFileName);
        long containerStartBeginTime = System.currentTimeMillis();
        EJBContainer ejbContainer =
EJBContainer.createEJBContainer(ejbContainerProperties);
        long containerStartEndTime = System.currentTimeMillis();
        logger.debug("Embedded container started in {} ms.",
(containerStartEndTime - containerStartBeginTime));
        EJBContainerReferenceHolder ejbContainerReferenceHolder =
EJBContainerReferenceHolder.getInstance();
        ejbContainerReferenceHolder.setEJBContainer(ejbContainer);
    }


On Fri, Dec 2, 2011 at 10:01 AM, Laird Nelson <ljnelson_at_gmail.com> wrote:
> On Fri, Dec 2, 2011 at 9:45 AM, Phillip Ross <phillip.w.g.ross_at_gmail.com>
> wrote:
>>
>> Similarly, any EMF/EMs I create from
>> javax.persistence.Persistence appear to be the same ones that are
>> injected into the EJBs.
>
>
> I confess I never even thought of that--to create a new EMF using the
> Persistence class and rely on the fact that it will just happen to share the
> L2 cache with all other EMFs in the container.  (Of course you're not really
> supposed to, but this is embedded testing, not production.)
>
> I think I'll stick with the MBean code, and that's only because I couldn't
> find any documentation on how many L2 caches, EclipseLink sessions and/or
> EntityManagerFactories are actually created when you have an arbitrary
> number of EJBs under test all injecting @PersistenceContexts into
> themselves.  With the MBean code as I have it written, I just rely on
> EclipseLink to invalidate everything--for any value of "everything" it
> wants.  :-)
>
> (Also, what value do you pass in for the String parameter required by the
> createEntityManagerFactory(String) call?
>
> Thanks for the tip, however!
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>