Hi, So the Aries JPA container uses the createContainerEntityManagerFactory method to build EMFs. This provides, amongst other things, a ClassLoader for the persistence unit. IMO JPA providers should use this to load config if it isn't found on their own classloader.
Regards, Tim Date: Tue, 6 Sep 2011 21:47:19 +0200 Subject: Re: Auditor and OSGi From: [email protected] To: [email protected] Thanks for your reply Tim, I agree, it seems like OpenJPA uses its own classloader to load my auditor implementation. That won't work of course. Is best practice for JPA providers to use the class loader for the bundle containing the persistence.xml? /Bengt 2011/9/6 Timothy Ward <[email protected]> This sort of problem is usually caused by a JPA provider using the wrong classloader to try and find your class. If you import the se.digia.maia.common.auditlog.impl package into your persistence bundle *and* OpenJPA uses the Persistence Unit classloader (rather than its own) to load it then everything should work fine. Realistically they should try both their classloader and the persistence unit classloader in case the config property is for their own internals. Unfortunately there is a limit to how much Aries can shield JPA providers from OSGi classloading! Regards, Tim Date: Mon, 5 Sep 2011 23:01:07 +0200 Subject: Auditor and OSGi From: [email protected] To: [email protected] I posted the following mail on OpenJPA's mailing list but got no answer. I'm posting it on the Aries mailing list as well since I suspect that this may rather depend on the JPA container in Aries than on OpenJPA itself. /Bengt ---- Hello everyone, After a long discussion about audit logging on this mailing list, Pinaki developed an audit logging facility that he describes on: http://openjpa.208410.n2.nabble.com/OpenJPA-Audit-Facility-tc6722915.html It provides very interesting functionality and I've tried it in simple JUnit scenarios using RESOURCE_LOCAL and it seems to work fine. However, my production environment nowadays is OSGi using Karaf+Felix. I use Aries for transaction support and also for it's JPA support. In that environment, OpenJPA doesn't seem to be able to find my auditor implementation (se.digia.maia.common.auditlog.impl.MaiaAuditor) that I specify in my persistence.xml. Has anyone else tried OpenJPA's new audit log facility? How can I make OpenJPA find classes specified in the persistence.xml? I have double-checked that the se.digia.maia.common.auditlog.impl is exported from my implementing bundle. I get the following exception: ERROR: Bundle org.apache.aries.jpa.container [21] EventDispatcher: Error during dispatch. (<openjpa-2.2.0-SNAPSHOT-runknown fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory".) <openjpa-2.2.0-SNAPSHOT-runknown fatal user error> org.apache.openjpa.persistence.ArgumentException: Could not invoke the static newInstance method on the named factory class "org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory". at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:76) at org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:147) at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:185) at org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62) at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:263) at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:153) at org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:283) at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453) at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237) at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413) at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807) at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729) at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610) at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3879) at org.apache.felix.framework.Felix.access$800(Felix.java:79) at org.apache.felix.framework.Felix$StatefulResolver.fireResolvedEvents(Felix.java:4491) at org.apache.felix.framework.Felix$StatefulResolver.resolve(Felix.java:4162) at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3557) at org.apache.felix.framework.Felix.startBundle(Felix.java:1797) at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1192) at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:266) at java.lang.Thread.run(Thread.java:662) Caused by: org.apache.openjpa.lib.util.ParseException: Instantiation of plugin "Auditor" with value "se.digia.maia.common.auditlog.impl.MaiaAuditor" caused an error "java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: se.digia.maia.common.auditlog.impl.MaiaAuditor". The alias or class name may have been misspelled, or the class may not have be available in the class path. Valid aliases for this plugin are: [default] at org.apache.openjpa.lib.conf.Configurations.getCreateException(Configurations.java:409) at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:219) at org.apache.openjpa.lib.conf.ObjectValue.newInstance(ObjectValue.java:124) at org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:103) at org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83) at org.apache.openjpa.conf.OpenJPAConfigurationImpl.getAuditorInstance(OpenJPAConfigurationImpl.java:1822) at org.apache.openjpa.kernel.AbstractBrokerFactory.postCreationCallback(AbstractBrokerFactory.java:854) at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.postCreationCallback(JDBCBrokerFactory.java:105) at org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:67) ... 21 more Caused by: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: se.digia.maia.common.auditlog.impl.MaiaAuditor at serp.util.Strings.toClass(Strings.java:164) at serp.util.Strings.toClass(Strings.java:108) at org.apache.openjpa.lib.conf.Configurations.newInstance(Configurations.java:211) ... 28 more /Bengt
