Issue Details (XML | Word | Printable)

Key: GLASSFISH-18508
Type: Bug Bug
Status: Closed Closed
Resolution: Invalid
Priority: Major Major
Assignee: Sanjeeb Sahoo
Reporter: aaronjwhiteside
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
glassfish

ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider

Created: 14/Mar/12 08:02 PM   Updated: 16/Mar/12 02:00 PM   Resolved: 15/Mar/12 05:45 AM
Component/s: classloader, OSGi
Affects Version/s: 3.1.2
Fix Version/s: None

Time Tracking:
Not Specified

Tags:
Participants: aaronjwhiteside and Sanjeeb Sahoo


 Description  « Hide

Using the workaround provided in:

http://glassfish.java.net/public/GF-OSGi-Features.pdf

Enabling the HybridPersistenceProviderResolver in osgi.properties and using the following code to create the EntityManagerFactory:

ClassLoader old = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader( OSGiEntityManagerFactoryFactory.class.getClassLoader() );
            EntityManagerFactory emf = Persistence.createEntityManagerFactory( persistenceUnitName );
            emf.createEntityManager().close();
            return emf;
        } finally {
            Thread.currentThread().setContextClassLoader( old );
        }

Produces the following exception, after 2 EntityMangerFactory's have been created. The third and fourth receive this error. Not sure why this succeeds in the first two bundles but fail in the others.

[#|2012-03-14T15:55:26.737-0400|WARNING|glassfish3.1.2|org.glassfish.osgijpa.extension|_ThreadID=101;_ThreadName=Thread-2;|Exception trying to instantiate cached provider by name org.eclipse.persistence.jpa.PersistenceProvider
java.lang.ClassNotFoundException: org.eclipse.persistence.jpa.PersistenceProvider not found by com.mm.mtrust.common.db [296]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at org.glassfish.osgijpa.extension.HybridPersistenceProviderResolver.convert(HybridPersistenceProviderResolver.java:155)
	at org.glassfish.osgijpa.extension.HybridPersistenceProviderResolver.readCache(HybridPersistenceProviderResolver.java:123)
	at org.glassfish.osgijpa.extension.HybridPersistenceProviderResolver.getPersistenceProviders(HybridPersistenceProviderResolver.java:104)
	at org.glassfish.osgijpa.extension.HybridPersistenceProviderResolver.getPersistenceProviders(HybridPersistenceProviderResolver.java:98)
	at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
	at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
	at com.mm.common.db.osgi.OSGiEntityManagerFactoryFactory.create(OSGiEntityManagerFactoryFactory.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:145)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:570)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:982)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:878)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:484)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:60)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:325)
	at org.eclipse.gemini.blueprint.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
	at org.eclipse.gemini.blueprint.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:290)
	at org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:137)
	at java.lang.Thread.run(Thread.java:722)


aaronjwhiteside added a comment - 14/Mar/12 09:25 PM

You can close this issue, turns out it was caused by something left in my osgi-cache folder, after deleting that and restarting the domain this issue disappeared.


Sanjeeb Sahoo added a comment - 15/Mar/12 05:45 AM

Not a bug as user had made some configuration mistakes.


aaronjwhiteside added a comment - 15/Mar/12 11:06 PM

Actually can you please re-open this bug. Turns out that clearing the osgi-cache has not effect, the issue is sporadic.

Some times it happens some times it does not, I just happened to work after I cleared the osgi-cache.


Sanjeeb Sahoo added a comment - 16/Mar/12 03:40 AM

Don't you have permission to open/close JIRA issues? Pl. attach a test case and reopen the issue.


Sanjeeb Sahoo added a comment - 16/Mar/12 05:19 AM

BTW, is the CNFE exception preventing your app to work or are you just worried by it being logged? HybridPersistenceProviderResolver code should fall back to discovering providers when it is unable to find providers in the cache.


aaronjwhiteside added a comment - 16/Mar/12 02:00 PM

I don't have permission to open/close JIRA issues.

Coming up with a test case might be difficult as it is sporadic. THE CNFE exception is preventing my application from loading a EMF.

I think this issue might be related to another I reported (read comments in that issue): GLASSFISH-18514

As the bundle org.glassfish.fighterfish.osgi-jpa has a run level of 2, and my jpa'd bundle has a run level of 1.