persistence@glassfish.java.net

RE: Problem between MacOSX and Windows (followup)

From: Manfred Riem <mriem_at_manorrock.org>
Date: Wed, 8 Nov 2006 13:38:25 -0700

Hi Marina,

I have been playing around with the tests some more and it seems that it has
to
do with classloader issues related to threads. Read the following scenarios

Scenario A:
1. NO System.out.println statement in Persistence Provider constructor
2. NOT Manually constructing Persistence Provider using default class
loader.
3. Manually constructing Persistence Provider using thread context loader.
4. Run the test that tries to use the Persistence Provider .... FAILS

Scenario B:
1. System.out.println statement in Persistence Provider constructor
2. NOT Manually constructing Persistence Provider using default class
loader.
3. Manually constructing Persistence Provider using thread context loader.
4. Run the test that tries to use the Persistence Provider .... SUCCEED

Scenario C:
1. System.out.println statement in Persistence Provider constructor
2. Manually constructing Persistence Provider using default class loader.
3. Manually constructing Persistence Provider using thread context loader.
4. Run the test that tries to use the Persistence Provider .... FAILS

Because of 2 being different in Scenario B and C I think it is definitely
a classloader issue with threading as an issue.

Kind regards,
Manfred Riem
mriem_at_manorrock.org
http://www.manorrock.org/
Founding Java Champion
-----Original Message-----
From: Marina.Vatkina_at_Sun.COM [mailto:Marina.Vatkina_at_Sun.COM]
Sent: Wednesday, November 08, 2006 11:20 AM
To: persistence_at_glassfish.dev.java.net
Subject: Re: Problem between MacOSX and Windows (followup)

Hi Manfred,

It can as well be a class loader issue. Can it be that a no-op constructor
called via 'loader.loadClass(s).newInstance()' throws an exception (for
whatever
reason) on MacOSX? Can you try?

You can also change the Persistence code and call findAllProviders() in the
static{} block instead to see if this is indeed a threading issue.

thanks,
-marina

Manfred Riem wrote:
> Hi there,
>
> I have done some more digging and it appears that the current
> implementation has a problem on MacOSX. I implemented my own
> Persistence Provider and if I do the following in its constructor it
successfully finds it.
>
> public MyPersistenceProvider() {
> System.out.println("Whatever");
> }
>
> If I comment out the System.out.println statement it cannot find this
> Persistence Provider. Looking at the code of the Persistence class I
> think it has to do with a threading issue. Can someone confirm this?
>
> Note my JUnit tests call Persistence.createEntityManagerFactory(String
> persistenceUnitName, Map properties)
>
> (see
> http://fisheye5.cenqua.com/browse/glassfish/persistence-api/src/java/j
> avax/persistence/Persistence.java?r=1.6#l48)
>
> Kind regards,
> Manfred Riem
> mriem_at_manorrock.org
> http://www.manorrock.org/
> Founding Java Champion